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

I have code something like this:


func _ready():
     if return_hello_world_after_a_second() == "Hello, World":

func return_hello_world_after_a_second():
      return yield(node2, "signalHello")


var t =
signal signalHello(text)

func _ready():
   yield(t, "timeout")

but instead it prints something like: [GDScriptFunctionState:1479]
How do i make it print hello, world?

note: also, this is sample code. The code in the game is essentially the same, but for a separate system.

Godot version 3.2
in Engine by (15 points)

1 Answer

+1 vote
Best answer

When you yield with a yield(t, "timeout") the calling function receives a GDScriptFunctionState. This object represents the function as it was interrupted. You can use yield(return_hello_world_after_a_second(), "completed") to wait for the actual return.

If a function does not always yield, or may yield multiple times, you get:
var result = return_hello_world_after_a_second()
while result is GDScriptFunctionState:
. result = yield(return_hello_world_after_a_second(), "completed")

Note that those yielding behaviors are likely to change somewhat in Godot 4.

by (2,720 points)
edited by

Thanks for answering my question! It helped a lot!

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.