Update connecting signal code for Godot 4 (#5587)

This commit is contained in:
Matthew
2022-04-29 06:51:14 -04:00
committed by GitHub
parent e0dfdf96ce
commit a6566b9152

View File

@@ -251,12 +251,12 @@ We can now connect the Timer to the Sprite2D in the ``_ready()`` function.
func _ready():
var timer = get_node("Timer")
timer.connect("timeout", self, "_on_Timer_timeout")
timer.timeout.connect(_on_Timer_timeout)
The line reads like so: we connect the Timer's "timeout" signal to the node to
which the script is attached (``self``). When the Timer emits "timeout", we want
to call the function "_on_Timer_timeout", that we need to define. Let's add it
at the bottom of our script and use it to toggle our sprite's visibility.
which the script is attached. When the Timer emits ``timeout``, we want to call
the function ``_on_Timer_timeout()``, that we need to define. Let's add it at the
bottom of our script and use it to toggle our sprite's visibility.
.. tabs::
.. code-tab:: gdscript GDScript