Skip to reading
Images, Carousels & Choice Controls

23. Restore controls from game data

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

A live variable binding writes out from a control. It does not automatically turn an existing control back into the value stored by a script or loaded game. Restore both the data and the visible controls deliberately.

Code example
extends "res://scripts/runtime/script_base.gd"
Code example
func run(_context: Dictionary = {}) -> Variant:
    var subtitles: bool = bool(
        Runtime.variables.get("show_subtitles", true)
    )
    var percent: float = float(
        Runtime.variables.get("art_opacity", 75.0)
    )
    await ChangeGUIElementProperty({
        "guiId": "settings_lab",
        "elementId": "subtitles_check",
        "property": "checked",
        "value": subtitles
    })
    await ChangeGUIElementProperty({
        "guiId": "settings_lab",
        "elementId": "opacity_slider",
        "property": "value",
        "value": percent
    })
    return true

Notice the different property names. Read the current check mark as button_pressed. Set its authored/rebuilt state using checked. A Slider uses value for both the live read and its constructed value.

The setter can rebuild these controls. Do not restyle a radio button or slider repeatedly while the player is dragging or choosing; that can reset transient state and keyboard focus.

Setting a control’s constructed checked or value property does not replace the need to store the intended preference. Keep the variable and control consistent rather than depending on a construction-time signal.

Page 43 of 52Permalink
Go to page