0 votes

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

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

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 (50 points)

1 Answer

0 votes
Best answer

I'm pretty sure you can do:

SomeOtherNode
    > SomeNode

# SomeNode.gd

signal some_signal

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

# SomeOtherNode.gd

func another_function():
    $SomeNode.some_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,581 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 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 webmaster@godotengine.org with your username.

Categories