0 votes

Hi, this is definitely a newbie question, but I must be misunderstanding something. I have a general idea of how signals work and how to handle them on the receiver side. However, the argument binding still doesn't make much sense to me, particularly for the built-in signals.

Specifically, I have a Button that needs to emit its built-in pressed() signal. It will be received by the root Node, and that works.

I see that the Connection editor allows me to add extra call arguments. I'd like to send a String variable called NAME, defined in the script for the Button, and then the root Node will do something with that String on signal.

Is this how binding is meant to be used or am I completely misinterpreting it? I haven't found the answer in the official documentation either, just that "you can bind an arbitrary number of arguments of (possibly) different types."

If I'm not misunderstanding, how do I specify that the bound argument is my NAME variable?

Alternatively, is there a way to access the Node that emitted the signal (there would be several instances in a scene), and get the NAME value that way?

Thank you :)

asked Mar 19 in Engine by firefly42 (15 points)

1 Answer

+1 vote
Best answer

Is this how binding is meant to be used or am I completely misinterpreting it?

Binding is like adding extra "metadata" to the connection, which then is available to the receiver. It is indeed a nice way to add a bit more context, or adapt to a function having different argument count. Adding your string should be fine.

If I'm not misunderstanding, how do I specify that the bound argument is my NAME variable?

In the editor, you can only define simple binding values (no arrays, no references). You also cannot refer to a variable of a script, the value is what you'll write in the editor. Basically, you have to write the value of NAME in the editor.

Alternatively, is there a way to access the Node that emitted the signal (there would be several instances in a scene), and get the NAME value that way?

It's not possible to do that from the editor, but it is possible with a connection made by scripts.

# Connects the button with a binding sending the button node itself
button.connect("pressed", root_node, "on_button_pressed", [button])

Any kind of value can fit, it's just that the editor is a bit limited to also allow them. They may not even save well in scene files, while a connection created by script can use any runtime value, which includes direct objects like nodes.

answered Mar 19 by Zylann (26,055 points)
selected Mar 19 by firefly42

Thank you for such a thorough answer, so far my scripting solution works (in line with what you offered), it just feels like an odd workaround but NAME will be changing across instances so I guess I'm keeping it this way~

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.