in your game, as I remember, you had something like "every 3 seconds, pick random enemy and shot"
But this value "3 seconds" cannot be changed as it is. You cannot transform an every 3 seconds into an every 2 seconds. 'Cause the value is kinda hard coded.
However, if you use something that represent a number instead of a real number, you just have to change this representation.
It's basically what's great about variable.
Let say I create a variable that represent the fire rate
let's call it fireRate. And let say it's a global variable 'cause it conserns many objects.
Ok so we have this variable. Now instead of "every 3 seconds" we write "every fireRate second"
Now you can modify however you want this representation. If you set fireRate to 2 it will be "every 2 seconds" if you set fireRate to 0.5 it will be "every half a second" etc.
The same idea goes with "in which level am I ?"
That's not the true question, the true question is "how many Level did I win?"
So you can have a variable named "level" to which you add 1 each time you win a level. But as a matter of fact, this value will also represent the level you're in, 'cause each time ou win, your level should increase.
And then you just have to put in a text box
set text to "Level "&level
In short variable are used to control what can vary in a program.
That's allYann2012-02-21 15:41:47