okkkk time for a TDO explanation ;D
sooo a for-loop is a possibility to do different things like:
getting every array, move npcs or just count something
an example
for(this.i=0;this.i < 5;this.i++){
playerx++;
}
this small code would move the player 5 fields to the right
explanation:
ok
for(this.i=0 ....
this is a starting value of a variable at the first time this.i will be 0
...;this.i < 5;...
and as long this.i is smaller the 5
...;this.i++){
this.i will get one added
so what it really does:
at the first time this.i is set to 0
it's smaller then 5
1 is added to this.i
the code in { } is executed with this.i=1
then back to the beginning
this.i is 1 so it's smaller then 5
so: this.i++ 1 is added to this.i and its 2
the code is executed with this.i = 2
and as long this.i is smaller then 5 the this.i gets 1 and the code is executed (so the playerx gets 5 times bigger)
so for arrays (don't want to explan arrays)
see this array: this.array={2,1,5,6};
if u had an array and wanted to check every element in it for a value (lets say if an element is 5) u can use a for loop
this.array={2,1,5,6};
this.lengt = arraylen(this.array); //this will get the elemts in the array
//now our checking for-loop
for(this.i=0;this.i < this.lenght;this.i++){
if(this.array[this.i]==5){
message Arraypos #v(this.i) is 5;
}
}
so the loop will start at the first array-pos (it's 0) and loop untill it got the full count of elements
It will start with 0
if(this.array[0]==5) //at the first time this.i would be 0
and check the first element of the array (here it's 2)
if this elemt is 5
==5
it would say: "Arraypos 0 is 5"
but because it's not 5 it will ignore this and add 1 to this.i
then the 2nd elemt of the array is checked etc.
Hope that's understandable
