Skip to reading
The Variable Designer

A complete GDScript puzzle check

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
Code example
extends "res://scripts/runtime/script_base.gd"
Code example
func run(_command_context: Dictionary = {}) -> Variant:
    if IfVariable("clock_wound", true):
        await ShowMessage({
            "text": "The clock is already running.",
            "duration": 4.0
        })
        return false
Code example
    await SetVariable({
        "name": "clock_wound", "value": true
    })
    await ChangeVariable({
        "name": "score", "operation": "add", "value": 10
    })
    await ShowMessage({
        "text": "Score: $$score", "duration": 4.0
    })
    return true

IfVariable checks the current Boolean. The early return ends this invocation after the “already running” message. It does not undo the flag. On the first call, the code continues, sets the flag and adds ten points.

Read a value when the script needs it#

Code example
var current_score = Variable.score.value
var safe_score = Runtime.variables.get("score", 0)
Variable.score.value = current_score + 5

Variable.score.value reads or writes the live shared value. The runtime .get form lets you supply a fallback if the ID is absent. Prefer the helpers or registry for writes: they notify the game so displays can refresh.

If you write directly to Runtime.variables in advanced native code, call Runtime.state_changed() afterward when the interface needs to refresh. The parameter name _command_context avoids confusing the run argument with the base script’s context member.

Page 28 of 37Permalink
Go to page