0 votes

"This is useful when a signal from many objects is connected to a single callback and the sender must be identified:

func _button_pressed(which):
    print("Button was pressed: ", which.get_name())

func _ready():
    for b in get_node("buttons").get_children():
          b.connect("pressed", self, "_button_pressed",[b])"

I'm trying to have a room that has 3 doors. Each door has an area which can emit a signal that when activated can turn a Boolean from false to true, but I wanna know which door sent the signal.

in Engine by (18 points)

1 Answer

0 votes

When You are calling emit_signal() You can pass whatever argument You like into this signal. Let one of argument be unique identity of your door, or reference to the door itself :

 on area_entered(body) :
         emit_signal("dooropened", body, self )

In example from documentation You quoted there is another option to pass arguments to a signal. You can specify arguments when connecting node to a signal. In this example [b] was chosen as an argument, that is always passed by nodes connected with this signal. And [b] is variable introduced in this loop, iterated among children of buttons, so it is the emitting node itself ! Every button was connected to pressing signal and forced to pass information about SELF in this signal.

After You specified number of arguments passed with signals, You have to remember, that callback function must intake the same number of arguments, or it will throw error

by (3,340 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.