From 5df18b894f04e95c49a47daec7428a46bb7f5fac Mon Sep 17 00:00:00 2001 From: HaSa1002 Date: Wed, 2 Sep 2020 14:09:06 +0200 Subject: [PATCH] Add yield with multiple arguments example to GDSCript Basics --- .../scripting/gdscript/gdscript_basics.rst | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/getting_started/scripting/gdscript/gdscript_basics.rst b/getting_started/scripting/gdscript/gdscript_basics.rst index 5a5a6a89d..65a24cf09 100644 --- a/getting_started/scripting/gdscript/gdscript_basics.rst +++ b/getting_started/scripting/gdscript/gdscript_basics.rst @@ -1591,6 +1591,24 @@ You can also get the signal's argument once it's emitted by an object: # Wait for when any node is added to the scene tree. var node = yield(get_tree(), "node_added") +If there are more than one argument ``yield`` returns an array containing +the arguments: + +:: + + signal done(input, processed) + func process_input(input): + print("Processing initialized") + yield(get_tree(), "idle_frame") + print("Waiting") + yield(get_tree(), "idle_frame") + emit_signal(input, "Processed " + input) + + func _ready(): + process_input("Test") # Prints: Processing initialized + var data = yield(self, "done") # Prints: waiting + print(data[1]) # Prints: Processed Test + If you're unsure whether a function may yield or not, or whether it may yield multiple times, you can yield to the ``completed`` signal conditionally: