yield question (godot documentation)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By devshin

Hello,
In the godot documentation for yield(), the example is given:

func _ready():

yield(countdown(), "completed") # waiting for the countdown() function to complete
print('Ready')

func countdown():

yield(get_tree(), "idle_frame") # returns a GDScriptFunctionState object to _ready()
print(3)
yield(get_tree().create_timer(1.0), "timeout")
print(2)
yield(get_tree().create_timer(1.0), "timeout")
print(1)
yield(get_tree().create_timer(1.0), "timeout")

prints:

3

2

1

Ready

Is the “Idle_frame” signal emitted immediately after _ready()? Even when ready is yielded?

Thank you for the help.

:bust_in_silhouette: Reply From: Inces

when You input a function into yield as argument, You also call it.
So countdown is called and ready is yielded. The rest of the function yields for external signals. Idle frame is emitted almost all the time, coming from underhood servers, so it unyields right after, leading to timer cascade. Last timer finishes the countdown(), so “completed” is finally triggered and ready()continues

Thank you so much Inces! This clarifies it perfectly.

devshin | 2022-10-08 12:12