6. Variables, constants and saved state
A variable gives a value a name. Use let for a working value in the current call. Use global for a runtime game variable, such as whether a puzzle is solved. Use const for a name that must not be reassigned.
global door_open: boolean = false
global score: integer = 0
const KEY_REWARD = 5function run()
let message = "The lock clicks."
if not door_open
set door_open to true
add KEY_REWARD to score
log(message)
end
return score
endA global initializer only fills a missing runtime variable. Calling this script a second time does not reset door_open to false or score to zero. Globals use the same runtime variable store as the Variable Designer, GUI bindings and saved game state.
A top-level let is initialized for each invocation; it is not a private persistent module variable in PCA Script. A local let inside a function is also call-local. For private session-only shared data, use the included-variable store described later. For story progress that must survive save/load, use a game variable.
Constants prevent rebinding the name. Do not treat a constant array or dictionary as deeply frozen data; keep mutable containers in ordinary variables. Avoid giving a local the same name as a global, a function, player, this or a namespace.
Figure 3. Game variables provide the saved puzzle state that PCA Script globals read and change.
