Arrays
From ZDoom Wiki
Arrays are groups of variables which are distingushed by indexed numbers. If you're familiar with C, Java, or any other language that supports arrays (which is most, if not all major ones), then you shouldn't have any problems, but here's a simple lesson for those not familiar with arrays.
To declare an array you use the following syntax:
int array1[4];
int array2[3] = { 1, 5, 9 };
str array3[2][2] = {{"This is", "a two"}, {"dimensional", "array"}};
As with all variables in ACS, every value of an array will be initialized to '0', so if you define a rather large array you need not worry about initializing every variable out of fear of referencing one without a number (that tip is for the C programmers out there, anyone else probably needn't worry). The number between the brackets is called the size when you're declaring it, and the index when you're accessing it (in scripts or functions). All arrays must have map, global or world scope (the last two are special case arrays though).
Probably the hardest part of arrays is the index variable in relation to the size. If you define an array with a size of four, you do so as in the first example above. However to access the fourth element, you must use array1[3] because the array indices start at 0. The easiest way to remember it is to just subtract one from the number you want. If you want the 10th element, you need to access index 9. If you want the first element, then you access index 0.
The main use of arrays is for print statements of sorts. For instance, say you want to have a different message print out depending on how many health potions out of 100 the player picks up in 30 seconds. If you want a different message for every ten (10, 20, 30 etc.) potions then you'd have to do something like this without arrays:
//this assumes you can only pick up potions in multiples of 10
//for simplicity's sake
//note that this could also be done better with a switch statement
script 1 (int potions)
{
if(potions == 0)
print(s:"You suck!");
else if(potions == 10)
print(s:"You're bad at this");
else if(potions == 20)
print(s:"You're okay sorta");
else if(potions == 30)
print(s:"You did kinda good");
else if(potions == 40)
print(s:"You're decent");
else if(potions == 50)
print(s:"Not too bad");
else if(potions == 60)
print(s:"Pretty good!");
else if(potions == 70)
print(s:"That was great!");
else if(potions == 80)
print(s:"Wow that's a lot of potions!");
else if(potions == 90)
print(s:"Nearly perfect!");
else if(potions == 100)
print(s:"Best potion picker-uper EVER!");
}
That's horribly long and ugly. Now with arrays you could simply define each string in an array as so and make the code much smaller:
//this also assumes you can only pick up potions in multiples of 10
str strings[11] = { "You suck!", "You're bad at this", "You're okay sorta",
"You did kinda good", "You're decent", "Not too bad",
"Pretty good!", "That was great!",
"Wow that's a lot of potions!", "Nearly perfect!",
"Best potion picker-uper EVER!" };
script 1 (int potions)
{
print(s:strings[potions / 10]);
}
And thus you've reduced that long script to a single line and an array. This also shows that you can have a math equation as the array index. If you notice the integer passed to script 1 is the number of potions, which is a multiple of 10 (so 0, 10, 20, ... , 90, or 100), so if you take that value and divide it by 10 you'll get the corresponding index. Therefore, collecting 20 potions will yield index 20 / 10 which is equal to 2, giving you index 2, meaning string 3 in the array, the message "You're okay sorta".

