Skip to reading
PCA Script Programming

6. Variables, constants and saved state

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 illustrations

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.

Code example
global door_open: boolean = false
global score: integer = 0
const KEY_REWARD = 5
Code example
function 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
end

A 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.

Page 13 of 357Permalink
Go to page