Variables and Counters
A variable is a named number or a piece of text that your events make and read. A counter is a variable you add to. A save keeps them.
Making and reading one
- set <var> <expr or words>
- Make or change a variable. Words that are not arithmetic become text.
- <var> = <expr or words>
- The same as
set, on any line of an event:torches = 3. - add <var> <expr>
- Add to a number. A negative amount subtracts. A variable that does not exist yet starts at 0.
- if <condition>
- Read it:
if wolves >= 3.
What set keeps, by what follows the name:
- "Words in quotes"
- Text, without the quotes:
set greeting "Well met"holdsWell met. - Another variable's name
- That variable's value, text or number:
set b acopiesa. - Arithmetic or a reading
- A number:
set q n + 1,set seen defeated(wolf). - Anything else
- The words as written, as text.
Text holds up to 63 letters.
[use]
set name "Bryn"
set who name
kills = defeated(wolf)
give wolf_token kills + 1
say {who} has felled {kills} wolves.give takes a count the same way: a number, a variable or a reading, give medal defeated(wolf) + 1.
[use]
add visits 1
if visits >= 3
say You have prayed here three times.
flag set shrine_blessed- Variables are shared: every line script sees them.
- A game holds up to 64 at once.
{visits}in asayline fills in the value.
In a save
A save keeps every variable, and a load puts them back. A new game starts with none.
In the save file a number is a var <name> <number> row and text is a vartext <name> <words> row.
In a test
A test's variables end with the test. The next Play starts with none, as a new game does.
Other things that count
- A flag
- On or off.
flag set <name>. See Events and Triggers. - A quest count
- A quest stage that counts kills, sales or uses for you.
- defeated(<type>)
- How many of an enemy type the player has defeated. See Bestiary.
- An item or a currency
count(<item>)andcurrency(<id>).- A custom property
- A number kept on one object, read with
prop(<prop>, <key>).
An old project
A save made before 0.7.3.1 has no such rows and loads with no variables, as it always did. Before 0.7.3.1 a variable lasted only until the next load, so a script that relied on a load clearing its variables should set them itself.