summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2019-12-16 08:49:32 +0100
committerGitHub <noreply@github.com>2019-12-16 08:49:32 +0100
commit74977277fac258060b111b31ec57ed2fa8b63398 (patch)
tree39edeb0ba8d020093716754a7bbf05c5776146d9
parent51ab6a96fd25b21f6c89143e04082f28c72379e2 (diff)
parent0fd7186971594a975cb4947e95f770798ae2f5c6 (diff)
Merge pull request #34280 from zaksnet/fix-yield-documentation
Fix documentation for yield
-rw-r--r--modules/gdscript/doc_classes/@GDScript.xml27
1 files changed, 15 insertions, 12 deletions
diff --git a/modules/gdscript/doc_classes/@GDScript.xml b/modules/gdscript/doc_classes/@GDScript.xml
index e84f84d788..c4b7e4887e 100644
--- a/modules/gdscript/doc_classes/@GDScript.xml
+++ b/modules/gdscript/doc_classes/@GDScript.xml
@@ -1377,23 +1377,26 @@
You can also use [code]yield[/code] to wait for a function to finish:
[codeblock]
func _ready():
- yield(do_something(), "completed")
- yield(do_something_else(), "completed")
- print("All functions are done!")
+ yield(countdown(), "completed") # waiting for the countdown() function to complete
+ print('Ready')
- func do_something():
- print("Something is done!")
-
- func do_something_else():
- print("Something else is done!")
+ 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:
- # Something is done!
- # Something else is done!
- # All functions are done!
+ # 3
+ # 2
+ # 1
+ # Ready
[/codeblock]
When yielding on a function, the [code]completed[/code] signal will be emitted automatically when the function returns. It can, therefore, be used as the [code]signal[/code] parameter of the [code]yield[/code] method to resume.
- If you are planning on calling the same function within a loop, you should consider using [code]yield(get_tree(), "idle_frame")[/code] also.
+ In order to yield on a function, the resulting function should also return a [code]GDScriptFunctionState[/code]. Notice [code]yield(get_tree(), "idle_frame")[/code] from the above example.
</description>
</method>
</methods>