Skip to content

Commit 3286e19

Browse files
kkoangakien-mga
authored andcommitted
doc: Use Signal.emit instead of emit_signal in Object examples
1 parent 9d6bdbc commit 3286e19

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

doc/classes/Object.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@
556556
While all options have the same outcome ([code]button[/code]'s [signal BaseButton.button_down] signal will be connected to [code]_on_button_down[/code]), [b]option 3[/b] offers the best validation: it will print a compile-time error if either the [code]button_down[/code] [Signal] or the [code]_on_button_down[/code] [Callable] are not defined. On the other hand, [b]option 2[/b] only relies on string names and will only be able to validate either names at runtime: it will print a runtime error if [code]"button_down"[/code] doesn't correspond to a signal, or if [code]"_on_button_down"[/code] is not a registered method in the object [code]self[/code]. The main reason for using options 1, 2, or 4 would be if you actually need to use strings (e.g. to connect signals programmatically based on strings read from a configuration file). Otherwise, option 3 is the recommended (and fastest) method.
557557
[b]Binding and passing parameters:[/b]
558558
The syntax to bind parameters is through [method Callable.bind], which returns a copy of the [Callable] with its parameters bound.
559-
When calling [method emit_signal], the signal parameters can be also passed. The examples below show the relationship between these signal parameters and bound parameters.
559+
When calling [method emit_signal] or [method Signal.emit], the signal parameters can be also passed. The examples below show the relationship between these signal parameters and bound parameters.
560560
[codeblocks]
561561
[gdscript]
562562
func _ready():
@@ -566,7 +566,7 @@
566566
player.hit.connect(_on_player_hit.bind("sword", 100))
567567

568568
# Parameters added when emitting the signal are passed first.
569-
player.emit_signal("hit", "Dark lord", 5)
569+
player.hit.emit("Dark lord", 5)
570570

571571
# We pass two arguments when emitting (`hit_by`, `level`),
572572
# and bind two more arguments when connecting (`weapon_type`, `damage`).

0 commit comments

Comments
 (0)