Setting variables is VERY useful in games.
There are many ways to add variables, and many variables that can be added.
I will talk about Number, String, Boolean, Array
So, lets say we are editing our movie clip actions, and we want to add variables. Remember when i talked about clipevent, and i said that variables should be added on LOAD? That's what we are going to do now:
onClipEvent (load) {
var life:Number = 5;
var scorestring:String = '';
var dead:Boolean = false;
var bgarray:Array = (1,0,0,0,1);
}
So in this code i set 4 different types of variables. lets talk about each one:
Number: numbers are variables that you can increaase, or decrease with actions. for example:
life -= 2;
i just decreased life by 2.
String: strings are lines, that you can edit, so usually you set it as blank ( '' ), and you add a string later on. For example:
scorestring = 'flawless';
now the scorestring is saying flawless.
Boolean: boolean variables are true or false. Use it when something can either be true, or false. For example:
if ( life <=0 ) {
dead = true;
}
what i am saying here is that if the number variable life is smaller or equal to 0, the boolean variable dead is no longer true, it is false.
Array: Have you ever seen the matrix ? A matrix is a 2 level array, just for the record. arrays are complex, but very useful once you master them.
Here is a 2 level array (matrix):
map1 = [[1,1,1,1,1,1,1,1,1],
[1,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,1],
[1,0,0,0,2,0,0,0,1],
[1,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,1],
[1,1,1,1,1,1,1,1,1]];
if you don't understand arrays, don't worry, when i start the tutorials, i will eventually make one with arrays and you will understand it =]
OBS: i said there are many ways to add variables, but i showed you 1 way. sorry. Those variables could also be added like this:
onClipEvent (load) {
life = 5;
scorestring = '';
dead = false;
bgarray = (1,0,0,0,1);
}
i think this way is easier, but you can do both.
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment