SpinBox Connecting and value input collection

Godot Version

GODOT 4.2.2Stable.official

Question

Hello, I have an options menu with several SpinBoxes. Each one allows for a float to be passed into it.
I need to collect each value input from the spin box and assign them to variables in another script.

Accomplishing the above js not a problem. As I can assign the signal of each SpinBox there own seperate func in the other script to collect each individual value that is emmited.

I want to make it look nicer by connecting all the SpinBoxes to one func that they all emmit their signal too. Then when the signal and input value is emmitted to the function in the other script and in the function they emmit too determine which SpinBox emitted the value and assign the emmited value to the corresponding variable.

Just attach an extra argument to the signal that allows you to identify the caller in the callback:

func _ready():
	$SpinBox.connect("value_changed", other_function.bind($SpinBox.name))

# ...

func other_function(value, caller_name):
	print(caller_name, value)

(If you don’t want to connect the signal via code, you can also provide “Extra Call Arguments” from the editor UI by toggling the “Advanced” toggle in the “Connect a Signal to a Method” popup.)

Note that instead of its name, you could also pass the calling node itself here – although that might lead to problems further down the line if that node gets free’d too early.

1 Like

Thank you for responding to help it is much appreciated!

I attached a screenshot of what I am trying to do. Sorry for not doing so sooner I did not have my computer with me at the time.

I am getting the name of the node which would work if I instanced each button separately and then queue freed them afterwards. However, I am trying to accomplish a multi-button system having each one as part of the node itself.

The function that all the buttons are connected too through the “node\signals” tab on each button is func _on_spin_box_value_changed(value) :

I want to receive the value from one of the buttons plus identify which button sent the value so that it can be assigned to the correct variable in the script.

I read that you mentioned something about “Advanced” toggle in the “Connect a Signal to a Method” popup however, I am struggling to locate that in the editor UI.

signal_connect

Doing it from a script (like in my example above) is less cumbersome, though.

1 Like

It worked perfectly thank you so much! You are absolutely brilliant!

I am very interested in learning more about the example you provided. I believe connecting it through script will be beneficial for another problem I am trying to work out.

I will say you have helped me solve this specific hurtle! Thank you so much!

I do not want to mark this forum as solved without exploring the various solutions possible. As versatility defeats adversity. Please find below my understanding of your previously proposed solution.

I agree that the scripting method is far less cumbersome and looks nice. I believe that during the loop of the array when establishing the connections we could also set the min_value, max_value, and step_value for each SpinBox button further reducing our encumbrance. It is fantastic and very clean.

I do have a question though. Seeing as the buttons run through the connection process the first time the script is compiled and executed will it maintain the connection from then on? Would any future iterations of the connection loop be redundant? If so I would like to find a way to check the connections, identify any failures, and repair the code, If it would be more resource efficient; However, I understand it is potentially negligible.

Post-Scipt:
I believe you also mentioned a third method. Would you be so kind as to help me understand the third solution? If I am mistaken and it is only the two; Then, I apologize for my misunderstanding of your written words. As always thank you very much!