Explorar o código

Demonstrate coroutine's completed signal

Apologies again for the spam.
Zirak %!s(int64=7) %!d(string=hai) anos
pai
achega
1f3275622d
Modificáronse 1 ficheiros con 15 adicións e 0 borrados
  1. 15 0
      getting_started/scripting/gdscript/gdscript_basics.rst

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

@@ -1388,6 +1388,21 @@ signal is received, execution will recommence. Here are some examples:
     # Wait 5 seconds, then resume execution
     # Wait 5 seconds, then resume execution
     yield(get_tree().create_timer(5.0), "timeout")
     yield(get_tree().create_timer(5.0), "timeout")
 
 
+Coroutines themselves use the ``completed`` signal when they transition
+into an invalid state, for example:
+
+::
+
+    func func():
+	    yield(button_func(), "completed")
+	    print("All buttons were pressed, hurray!")
+
+    func button_func():
+        yield($Button0, "pressed")
+	    yield($Button1, "pressed")
+
+``func`` will only continue execution once both the buttons are pressed.
+
 Onready keyword
 Onready keyword
 ~~~~~~~~~~~~~~~
 ~~~~~~~~~~~~~~~