Skip to reading
Images, Carousels & Choice Controls

17. Read a slider’s live value

Edition 0.86.4.1 HF1

0.86.4.1 Hotfix 1 edition. Earlier lessons and screenshots retain their original version context; revised references and supplements describe the newer behavior.

Download PDFView PDF page

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.

Code example
extends "res://scripts/runtime/script_base.gd"
Code example
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 true

1. 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.

Page 32 of 52Permalink
Go to page