Choose where to store a value
On this page
LESSON 20
How long should the game remember something? Answer that first. The right place to store it follows from that decision.
A value for one calculation#
local price = 4
local quantity = 3
local total = price * quantityInside run, these names exist while that function is running. A later call can calculate a different total without carrying over an old purchase.
A value for the current session#
A local declared above the functions belongs to the script instance. With Keep global instance alive selected, the same instance can count room arrivals. Programming page 15 shows that counter and the matching event handler.
A value other scripts and save slots need#
await(SetVariable({ name = "met_keeper", value = true }))
if IfVariable("met_keeper", true) then
Log("The keeper recognizes the player.")
endThis fragment assumes a Boolean game variable with ID met_keeper and a starting value of false. Another record can read the same flag later, even after the player changes rooms. Load a game slot to restore the progress captured when that slot was saved.
A displayed name, a line of dialogue and a saved flag can all describe the same event. Decide which stored value tells the game what actually happened.
