Ver código fonte

Added looped Coroutine Example to GDScript Basics (#2586)

Johannes Witt 5 anos atrás
pai
commit
1eab94c72d

+ 14 - 0
getting_started/scripting/gdscript/gdscript_basics.rst

@@ -1482,6 +1482,20 @@ Will print::
     world
     cheers!
 
+Remember to save the new function state, when using multiple ``yield``s:
+
+::
+    func co_func():
+        for i in range(1, 5):
+            print("Turn %d" % i)
+            yield();
+    
+    func _ready():
+        var co = co_func();
+        while co is GDScriptFunction && co.is_valid():
+            co = co.resume();
+
+
 Coroutines & signals
 ^^^^^^^^^^^^^^^^^^^^