How can you set a variable to the value of a slider?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ZombieGame007
:bust_in_silhouette: Reply From: Zylann

Get the slider node, and access its value property:

var slider = get_node("Path/To/Slider")
my_variable = slider.value

If you want to update your variable only when the value changes, connect the value_changed signal to the node on which your script is.

func _on_Slider_value_changed(new_value):
    my_variable = new_value

Note: I assume you have my_value declared as a member variable on top of your script.

How to access properties on a node?

ZombieGame007 | 2019-12-01 17:26

I just wrote it above. You use . followed by the name of the property. If you have your slider in the slider variable, accessing value is done by writing slider.value.

Zylann | 2019-12-01 17:27

Hey man, just found this. Do you think it would be possible to apply the value of a volume hslider to a global script? I want the game to remember the value of the hslider as well as the volume it gives when I enter a new scene but I don’t know how to implement it. | 2021-09-14 21:55