What is a variable?

Every program you create is going to share a bunch of common elements, one of which are variables. They are used to store information that your program needs. Take the example of a Space Invader style game. A game like this will need to store data, such as how many lives the player has left, how many points they have scored, how many enemies are still alive etc. This is where variables come into play. You can use them to deal with all the data that your game requires.

A variable can be declared in your program by giving it a name and assigning it a value. Say our game requires a variable to hold the score. It could be set up like this.

score = 0

do print ( score ) sync ( ) loop

The first line has declared a variable named score and assigned it a value of 0. Following on from that there's a do loop, that will display the contents of score on screen by calling the print command and passing in score as its parameter. If you run the program all you will see on screen is the number 0 in the top left corner.

image-1