+1 vote

This is in some function:
emitsignal("variablechanged", name)

Then, elsewhere, I want to do something like this:
yield(getnode("."), "variablechanged(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?

in Engine by (20 points)

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?

1 Answer

+3 votes
Best answer

You could yield in a loop like

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

Better version suggested by Zylann:

while yield(self, "variablechanged") != "my_variable":
by (238 points)
selected by

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

Right, sorry.

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.