Yielding on emitted signals with specific arguments?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Anne
:warning: Old Version Published before Godot 3 was released.

This is in some function:
emit_signal(“variable_changed”, name)

Then, elsewhere, I want to do something like this:
yield(get_node(“.”), “variable_changed(my_variable)”)

I want to yield when that signal is emitted, but only when “my_variable” is passed into the signal. How can I do this?

I can’t imagine what you’re trying to achieve with that kind of program flow. If you want to issue a yield when a signal is fired, that happens inside the function that is connected to the signal. It will only affect the code inside the signal function, but I get the impression you’re wanting to yield elsewhere. Signals are processed at a very specific time so they’re not going to randomly jump inside of any function.

Yield acts a lot like a return statement, but when resume is called it goes back to where it exited and continues execution.

Can you give a description of what you’re trying to do?

avencherus | 2017-02-16 10:05

:bust_in_silhouette: Reply From: raymoo

You could yield in a loop like

while yield(getnode("."), "variablechanged") != "my_variable":

Better version suggested by Zylann:

while yield(self, "variablechanged") != "my_variable":

get_node(".") is a useless call, you can use self directly

Zylann | 2017-02-16 20:50

Right, sorry.

raymoo | 2017-02-16 20:55