| Reply From: | wombatstampede |
You can pass an additional parameter when you connect the signal to the button.
You can do this either interactively in the node connect dialogue…
or you can add a parameter when you connect the button to the signal which usually is more flexible.
This is usually done in the _ready part of your script.
See the section about “Signals” here:
…to see how signals are connected with parameters.
Yeah @wombatstampede, I know that, but all parameters are always primitive types. No one are a reference to it self. Am I Wrong? image hosted at ImgBB — ImgBB
Raikish | 2019-01-02 11:43
This may be the case for the interactive linking. But you can definitely do it via scripting. There’s even an example for that on the page which I linked.
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])
Natrually, that loop in _ready is just an example. It may be advisable to put such a loop in a separate function and call it itself (recursive) in case a node has children on its own. You can also check a node with i.e. “if b is Button:” or “if b is GroupButton:” to limit the connect to buttons only.
wombatstampede | 2019-01-02 13:26