Arrays are groups of related variables which share the same name but are distinguished by an "index" number. For example, you might store the months of the year in an array - month[1] would be "January", month[2] would be "February", etc.
It's simple to set up an array in Quest - there's no need to declare it before you use it. For example, for our months array, we could use:
set string <month[1]; January> set string <month[2]; February> set string <month[3]; March> . . . set string <month[12]; December>
We can then read the contents of our array in exactly the same way as we can for ordinary string or numeric variables. For example:
msg <Month 6 is #month[6]#.>
So far this does not actually add anything new - after all, there's nothing to stop us creating variables such as #month6# or #monthsix# anyway. But arrays come into their own when you need to use another variable to look at the contents of a particular element of the array. For example, we might want a user to be able to type a number from 1 to 12 and report back the correct month. This would not be possible without arrays (unless we typed in a lot of very tedious code). But with arrays it becomes easy:
msg <Enter a number from 1 to 12:> enter <number> ' "enter" returns a string variable so convert to a numeric variable: set numeric <monthnumber; #number#> msg <Month number %monthnumber% is #month[monthnumber]#.>
Note that we do not use the normal "%" characters around monthnumber when it appears as the array index.
Another, simpler, example is printing out all twelve months:
for <i;1;12> msg <#month[i]#>
The upper bound of an array is the highest index that has been set. In our example the upper bound is 12, because month[12] is the highest array index we have set. If we try to get the value of #month[15]# we will get an error. The upper bound of an array can be obtained by calling the ubound function.