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.