23. Restore controls from game data
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.
extends "res://scripts/runtime/script_base.gd"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 trueNotice 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.
