GodotObject.connect

Connects a signal to a method on a target object. Pass optional binds to the call as an Array of parameters. These parameters will be passed to the method after any parameter used in the call to emitSignal. Use flags to set deferred or one-shot connections. See connectflags constants. A signal can only be connected once to a method. It will throw an error if already connected, unless the signal was connected with constant CONNECT_REFERENCE_COUNTED. To avoid this, first, use isConnected to check for existing connections. If the target is destroyed in the game's lifecycle, the connection will be lost.

struct GodotObject
@nogc nothrow
GodotError
connect
(
in String signal
,,
in String method
,
in Array binds = Array.make()
,
in long flags = 0
)

Examples

connect("pressed", self, "_on_Button_pressed") # BaseButton signal connect("text_entered", self, "_on_LineEdit_text_entered") # LineEdit signal connect("hit", self, "_on_Player_hit", weapon_type, damage ) # User-defined signal

An example of the relationship between binds passed to connect and parameters used when calling emitSignal:

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)

Meta