Quote:
Originally Posted by khortez
Edit: messed up on something, it wasn't
PHP Code:
(player.direction[1])
it was:
PHP Code:
temp.x = (player.x + vecx(player.dir) * 1.5) + this.origins[player.dir][0];
temp.y = (player.y + vecx(player.dir) * 2) + this.origins[player.dir][1];
been doing quite a bit of editing to this script, trying to understand its functions and what not etc. And this wasn't copied/pasted. so yeah sorry about that. If someone could, could they re-explain those lines?
|
In that case, this.origins is a multi-dimensional array, sort of like matrices.
Arrays store multiple variables.
PHP Code:
temp.array = {"Hello", "World", "!"};
echo(array[0] SPC array[1] @ array[2]);
The first line defines the array, containing the strings "Hello", "World", and "!".
The second line outputs "Hello World!" on RC. To get a specific variable from an array, you need [#], where the number inside braces ([]) relates to the position in the array starting at the lowest integer 0, so "Hello" is 0, "World" is 1, and "!" is 2.
Now for multi-dimensional arrays.
PHP Code:
temp.array = {{"Hello", "World", "!"}, {"Nice", "day", "we're", "having", "!"}};
echo(array[0][0] SPC array[0][1] @ array[0][1]);
echo(array[1][0] SPC array[1][1] SPC array[1][2] SPC array[1][3] @ array[1][4]);
The first line defines the array, with as the first variable and another array as the second.
The second line outputs "Hello World!" on RC. It gets the first array's variables with array[0][#].
The third line outputs "Nice day we're having!" on RC. It gets the second array's variables with array[1][#].
Also, please stop with all the enters.
Quote:
Originally Posted by Jiroxys7
so
PHP Code:
for (temp.i = 0; i < 10; i ++) { echo(i); }
and
PHP Code:
for (temp.number : array) { echo(number); }
pretty much do the same thing and are just personal preference?
|
For Loops
PHP Code:
for (A; B; C) {
D
}
Use A as a number to do D (or just to do D the amount of times between A with a C increase/decrease and B)
For-Each Loops
PHP Code:
for (A : B) {
C
}
Use A as each of the variables in B (array) in order to do C.
For-each loops are simplified from this.
PHP Code:
for (temp.i=0; temp.i<array.size(); temp.i++) {
temp.v = array[i];
//do things with v
}
Too much explaining...