Function 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.
godot .core .defs .GodotError connect
(
const(String) signal,
GodotObject target,
const(String) method,
const(Array) binds = make(),
const(long) flags = 0L
) nothrow @nogc;
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)