View Single Post
  #14  
Old 01-30-2002, 11:15 AM
Faheria_GP2 Faheria_GP2 is offline
Banned
Faheria_GP2's Avatar
Join Date: Oct 2001
Posts: 1,177
Faheria_GP2 is on a distinguished road
Quote:
Originally posted by BocoC
Ugh. Explaining arrays to Brandon was tough. Let me see:

Arrays are basically 1 variable that can hold multiple values. In Graal, arrays are 1 dimensional. Let's take a look at an array:

this.myarray={5,2,6,2,3};

This.myarray holds 6 independant values. You retrieve a value by putting the index of the value inside brackets [ ] after the variable:

this.myarray[2] returns the number 6. The letter 5 is index 0, 2 is index 1, 6 is index 2, ect, ect.

People normally use arrays to organize lots of similar data. Here is great use of arrays and keydowns:
NPC Code:

if (created) {
this.keys={0,0,0,0,0,0,0,0,0,0,0}; //Initialize an array with 11 values from 0 to 10
timeout=0.05;
}
if (timeout) {
GetKeys();
timeout=0.05;
}
function GetKeys() {
for (i=0;i<11;i++) this.keys[i]=keydown(i);
}


This will return the state of all 11 keydowns in a nice little variable called this.keys. You can then check if certain keys are down inside your code by checking a value in the array. If the D key was down, this.keys[4] will return 1.

I hope this helps. From my experience, I learned that teaching arrays is hard.
gawd, use setarray
Reply With Quote