diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2019-11-21 10:36:15 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-21 10:36:15 +0100 |
commit | 3d74bbe72068affb195800a1a5cb620431285d9e (patch) | |
tree | c17018bd80ac4aba666051e6ccfafdb2469faa89 /doc/classes | |
parent | 2981915f19f6c168128afffcfe18fcd122401b65 (diff) | |
parent | b81f9f777f3b621bc5b8970eabd8d93d1db453b9 (diff) |
Merge pull request #33312 from BenjaminNavarro/master
Better description of the binds parameter of connect
Diffstat (limited to 'doc/classes')
-rw-r--r-- | doc/classes/Object.xml | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/doc/classes/Object.xml b/doc/classes/Object.xml index 4b77197e29..5a09fe39c0 100644 --- a/doc/classes/Object.xml +++ b/doc/classes/Object.xml @@ -139,7 +139,7 @@ <argument index="4" name="flags" type="int" default="0"> </argument> <description> - Connects a [code]signal[/code] to a [code]method[/code] on a [code]target[/code] object. Pass optional [code]binds[/code] to the call as an [Array] of parameters. Use [code]flags[/code] to set deferred or one-shot connections. See [enum ConnectFlags] constants. + Connects a [code]signal[/code] to a [code]method[/code] on a [code]target[/code] object. Pass optional [code]binds[/code] to the call as an [Array] of parameters. These parameters will be passed to the method after any parameter used in the call to [method emit_signal]. Use [code]flags[/code] to set deferred or one-shot connections. See [enum ConnectFlags] constants. A [code]signal[/code] can only be connected once to a [code]method[/code]. It will throw an error if already connected, unless the signal was connected with [constant CONNECT_REFERENCE_COUNTED]. To avoid this, first, use [method is_connected] to check for existing connections. If the [code]target[/code] is destroyed in the game's lifecycle, the connection will be lost. Examples: @@ -148,6 +148,13 @@ connect("text_entered", self, "_on_LineEdit_text_entered") # LineEdit signal connect("hit", self, "_on_Player_hit", [ weapon_type, damage ]) # User-defined signal [/codeblock] + An example of the relationship between [code]binds[/code] passed to [method connect] and parameters used when calling [method emit_signal]: + [codeblock] + connect("hit", self, "_on_Player_hit", [ weapon_type, damage ]) # weapon_type and damage are passed last + emit_signal("hit", "Dark lord", 5) # "Dark lord" and 5 are passed first + func _on_Player_hit(hit_by, level, weapon_type, damage): + print("Hit by %s (lvl %d) with weapon %s for %d damage" % [hit_by, level, weapon_type, damage]) + [/codeblock] </description> </method> <method name="disconnect"> |