Variables
Variables hold information about your game and the objects in it. Things like a character's name or hit points (in other words, literals). Anytime you need you need to reserve computer memory to store a number or piece of text, you will store them in a variable.
*English*
The character's hit points are 120.
*Code*
hitPoints = 120
*English*
The character's name is Bob, the Thunderous.
*Code*
charName = "Bob, the Thunderous"
*Format*
variable = literal
The equals sign ( = ) is called an assignment operator. It will take the data on the right side and stores it in the variable on the left.
Once you have given a variable a bit of data to handle, you can change the data anytime by using the assignment operator again.
*English*
The character's hit points are 25.
Nope, now they are 50.
*Code*
hitPoints = 25
hitPoints = 50
*English*
The character's name is Leroy.
Now, the character's name is Lennie.
*Code*
cName = "Leroy"
cName = "Lenny"
More Examples
*English*
The score starts at 0.
*Code*
score = 0
*English*
The cat has nine lives.
*Code*
cat_lives = 9
page revision: 3, last edited: 12 May 2007 16:33