Skip to main content

Variables

A variable is a named value the game remembers while it runs: Score, Lives, PlayerName, DoorOpen. Each variable is a Number, Text or Yes / No (boolean).

Kinds of variables​

KindLives…Reset when…Create it in
Globalin every scenenever (while the game runs)Scene tab → Global variables, or a variable row at the top of an event sheet
Scenein one scenethe scene startsScene tab → Scene variables
Localinside one event, group or function (and its sub-events)every time that event runs (unless static)Event menu → Add local variable
Instanceon each copy of an objectthe object is createdInspector → Instance variables
Scene and global variables (Scene tab)
Scene and global variables (Scene tab)
Instance variables (Inspector)
Instance variables (Inspector)

You can also create a variable while filling in an action: pick + New variable… in the Variable list.

Using variables in events​

To…Use
Test a valueCompare variable (Score ≥ 10), Compare instance variable (Enemy.health ≤ 0)
Change a valueSet variable, Add to variable, Subtract from variable, Toggle variable (Yes/No)
Change an object’s valueSet / Add to / Subtract from instance variable
Show itIn any expression: "Score: " + Score, Enemy.health

Text variables: Add to variable appends text.

Saving between game sessions​

Variables are forgotten when the game closes. To keep a high score or unlocked levels, use:

  • Save value — stores a value on the device under a save name. Leave Value empty to save the variable with the same name.
  • Load value — reads it back into a variable (nothing happens if it was never saved). Leave Variable empty to load into the variable with the same name.

Example — best score:

ConditionsActions
⚡ On start of sceneLoad value best into Best
Score > BestSet Best to Score · Save value best = Best

Scripts: game.save('best', 10), game.load('best').

Names​

Variable names use letters, numbers and _, and can’t start with a number. They are case-sensitive: score and Score are different.