A complete GDScript puzzle check
extends "res://scripts/runtime/script_base.gd"func run(_command_context: Dictionary = {}) -> Variant:
if IfVariable("clock_wound", true):
await ShowMessage({
"text": "The clock is already running.",
"duration": 4.0
})
return false await SetVariable({
"name": "clock_wound", "value": true
})
await ChangeVariable({
"name": "score", "operation": "add", "value": 10
})
await ShowMessage({
"text": "Score: $$score", "duration": 4.0
})
return trueIfVariable 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#
var current_score = Variable.score.value
var safe_score = Runtime.variables.get("score", 0)
Variable.score.value = current_score + 5Variable.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.
