Skip to reading
BASIC Scripting

Decide how long data should live

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

THE BASIC LANGUAGE

A counter used during one calculation, a counter private to a record, and a flag saved with the game each need a different home.

Code example
DIM visits AS Integer = 0
Code example
FUNCTION Run()
    visits += 1
    RETURN visits
END FUNCTION

What you should see Two calls to the same unchanged record returned 1 and 2. The DIM sits above FUNCTION, so both calls see the same private counter.

Code example
GLOBAL signal_seen AS Boolean = FALSE
Code example
FUNCTION Run()
    signal_seen = TRUE
    RETURN signal_seen
END FUNCTION

GLOBAL uses the game’s shared, saveable variables. In the editor runtime, saving with signal_seen true, clearing it, and loading the slot restored true. Use a distinct name for every flag that means something different.

Source table from Decide how long data should live, page 8
Inside a functionDIM belongs to that call. It starts again next time.
At the top of the recordDIM or top-level STATIC retains private state until the module/cache is reset. Editing or reloading can reset it.
Across records and savesGLOBAL or SHARED gives other records and the save system access. Local STATIC inside a function is unsupported.
Page 8 of 86Permalink
Go to page