This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

Is there a way of doing something like a maybe monad? Something like this:

yield(function(args), "a_signal", result)
if result:

I think it would be excellent if I can do this since I don't have to implement a new method for each method I want to trigger based on a specific result.

in Engine by (52 points)

1 Answer

+1 vote
Best answer

I'm pretty sure you can do:

    > SomeNode


signal some_signal

func some_function():
    emit_signal("some_signal", <value>)


func another_function():
    var value = yield($SomeNode, "some_signal")

Of course this configuration is just an example, but the main idea is you can retrieve the values passed to emit_signal(<signal>, <values1>, <value2>, ...). I don't know offhand how multiple values are passed back - my guess would be an array but you'll have to do some testing with that.

by (1,663 points)
selected by

Thank you. Indeed the values returned by yield are retrieved in a array. The tricky part is that those types are valid when there is more than one param. When we have only one param, we'll end up having the non wrapped value x.x.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.