Godot: Can't edit spinbox using a slider and vise versa

Created on 5 May 2019  路  9Comments  路  Source: godotengine/godot

I believe this is a bug in Godot, reported it on reddit

https://www.reddit.com/r/godot/comments/bkr2ze/cant_edit_spinbox_using_a_slider_and_vise_versa/

This is the code

extends SpinBox

func _on_raise_input_value_changed(number):
     get_node("../HSlider").value = number

func _on_HSlider_value_changed(value):
    var slider = get_node("../HSlider").value
    var raise = (slider/100) * Global.chips
    get_node("../raise_input").value = raise

What this does is if you change the spinbox it updates the slider and vise versa, it works with lineEdit not spinbox, I have to use spinbox because

1- I'm interested in numerical values only, regex is weird sometimes

2 - I want to open the numpad on mobile.

spinbox to slider does not work at all. Whereas Slider to Spinbox works, but the slider move from min to max in an instant and I cannot control it, also I cannot move it back. So it goes from 0 to 100 and gets stuck there

archived core

Most helpful comment

There is a share() method under the Range Controls, like slider, scrollbar, progressbar, spinbox...

extends Control

func _ready():
    $HSlider.min_value = $SpinBox.min_value
    $HSlider.max_value = $SpinBox.max_value
    $HSlider.share($SpinBox)

here's the demo how it works.

share

All 9 comments

Problem solved on Reddit, I quote

Actually when you connect them to each other and change value from code signal fires back if modified value is different from own, like in your case where you divide it by 100 and multiply by Global.chips... So it start chain reaction until maximum or minimum value reached. I guess your Global.chips is bigger then 100, that's why your value jumps to maximum instead of minimum.

Anyway to fix this you should modify HSlider proportionally

get_node("../HSlider").value = number * 100 / Global.chips

or remove modifiers and assign exact values.

It still a bit buggy though, I wish it could be fixed, if you'd like me to close the issue please let me know.

There is a share() method under the Range Controls, like slider, scrollbar, progressbar, spinbox...

extends Control

func _ready():
    $HSlider.min_value = $SpinBox.min_value
    $HSlider.max_value = $SpinBox.max_value
    $HSlider.share($SpinBox)

here's the demo how it works.

share

@volzhs Awesome! I didn't find it though, not in the inspector nor in the signal, could you let me know how to get to it?

Should I attach the script to a control then right? Right now I have a parent control and then its children are the slider and input field.

I guess you just pass the min/max value to the slider control like i attached about script.
I have been using godot engine for years and just tried to read and learn what godot can do from docs. :smile:

not sure it's a bug, but about docs or something?

I havent tried it today, will do tomorrow and let you know. thanks for everything :) your tip is amazing

@volzhs Just tried it, worked perfectly, I even can setup the min value and max value

func _ready():
    $SpinBox.min_value = 50000
    $SpinBox.max_value = 5000000

    $HSlider.min_value = $SpinBox.min_value
    $HSlider.max_value = $SpinBox.max_value
    $HSlider.share($SpinBox)

Not sure if I should close the issue or not, your code solved my problem but the original bug is still there in case one doesn't use share.

I guess there's a logical error with your code or setting wrong value, like proper min/max/steps values or calculating values of the 2 nodes.
can you share a minimal project for it?

No need I'll just close the issue since your code has worked perfectly.

Was this page helpful?
0 / 5 - 0 ratings