Can someone explain this function of signals a little better

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By fat_furius

"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.

:bust_in_silhouette: Reply From: Inces

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