View Single Post
  #9  
Old 08-09-2010, 07:37 PM
Switch Switch is offline
o.o
Switch's Avatar
Join Date: Jan 2007
Location: Philadelphia
Posts: 3,038
Switch has a spectacular aura about
Send a message via MSN to Switch
Quote:
Originally Posted by khortez View Post
Edit: messed up on something, it wasn't
PHP Code:
(player.direction[1]) 
it was:
PHP Code:
temp.= (player.vecx(player.dir) * 1.5) + this.origins[player.dir][0];

temp.= (player.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[
0SPC 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][0SPC array[0][1] @ array[0][1]);
echo(array[
1][0SPC array[1][1SPC array[1][2SPC 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 View Post
so
PHP Code:
for (temp.010++) { 
  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 (ABC) {
  
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 (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=0temp.i<array.size(); temp.i++) {
  
temp.= array[i];
  
//do things with v



Too much explaining...
__________________
Oh squiggly line in my eye fluid. I see you lurking there on the peripheral of my vision.
But when I try to look at you, you scurry away.
Are you shy, squiggly line?
Why only when I ignore you, do you return to the center of my eye?
Oh, squiggly line, it's alright, you are forgiven.
Reply With Quote