17. Read a slider’s live value
You can use a slider without a variable binding. A separate Button can read its current value, apply it and store it in a game variable.
extends "res://scripts/runtime/script_base.gd"func run(_context: Dictionary = {}) -> Variant:
var percent: float = float(GetGUIElementProperty(
"settings_lab", "opacity_slider", "value", 75.0
))
await SetVariable({
"name": "art_opacity", "value": percent
})
await ChangeGUIElementProperty({
"guiId": "settings_lab",
"elementId": "settings_art",
"property": "opacity",
"value": clampf(percent / 100.0, 0.0, 1.0)
})
return true1. Add an Image with ID settings_art and choose a picture for it.
2. Create a Number variable named art_opacity, with initial value 75.
3. Create and apply this script. Add an Apply Button that runs it.
4. In gameplay, move the slider to about 25 and press Apply. The picture should become much more transparent.
The slider uses 0 to 100 because that is easy to read as a percentage. The Image’s opacity uses 0 to 1, so the script divides by 100. The slider changes the value; the script makes that value do something.
