Chapter 0.2: Storing Information - Variables & Data Types
To create rules, we first need to be able to store and label information. Imagine you want to create a puzzle where a door only opens after three buttons are pressed. You need to keep track of how many buttons have been pressed.
This is the job of a variable. A variable is a named container for a piece of data.
In Squirrel, the most common way to create a temporary variable is with the local keyword, followed by a name, an equals sign (=), and the data you want to store.
// This creates a variable named 'buttonsPressed' and stores the number 0 in it.
local buttonsPressed = 0
// This creates a variable to store the name of the current test chamber.
local chamberName = "Escape Route Alpha"
// This variable stores whether the exit door is currently unlocked.
local isDoorUnlocked = false
The text after a // is a comment. The engine ignores it completely. Use comments to leave notes for yourself and others explaining what your code does.
Fundamental Data Types
Variables can hold different types of data:
- Integer: Any whole number, positive or negative (
-10,0,3,9999). - Float: Any number with a decimal point (
-0.5,3.14159,100.0). - String: A sequence of text characters, always enclosed in double quotes (
" "). - Bool (Boolean): Can only ever be one of two values:
trueorfalse. - Null: A special type that represents "nothing" or "no value".