Arrays are essentially just list of data, much like a column a values in a spread sheet. In ComScript (and most languages) an array has a name (e.g. my array) and a index that refers to the location or address of the value stored in the array. Staying with the spreadsheet analogy, the name of the array would equate to the column header or description in the first row and the index would be the row number. Let's look a the example data below.
Name TestScore
Jim 89
Jane 100
Joe 67
Betty 92
Fred 96
The above data could be easily loaded into two (parallel) arrays, Name and TestScore. In more complicated languages, arrays indexes begin with 0, but ComScript lets you index your array to any number, although we suggest 0 or 1 so it's easier to follow. Here, we could assign "Jim" to array Name at position 1. A simple way to do that in ComScript would be: <set var="Name@1" value="Jim" /> and then <set var="TestScore@1" value="89" />. The @ symbol tells ComScript that this variable is an array and it position follows the @ symbol. You could assign all of the above names and scores with individual set commands or, if the data was in a file, you could read in each line and parse the data into array variables inside a readfile loop.
Lets assume that the name and score lists above are written in a file called MathTest1.txt. The following code would load the two column headers, and all the names and scores into two arrays.
<set var="i" value="0" /> <!-- initialize readfile loop counter and array index to 0 -->
<!-- read individual lines from MathTest1.txt into DataLine until the end of the file -->
<readfile var="DataLine" file="MathTest1.txt" >
<!-- Parse each DataLine into the array variables -->
<loadvars string="[DataLine]" vars="Name@[i],TestScore@[i]" type="string" delimiter=" " multi="True" />
<math var="i" expression="[i]+1" /> <!-- increment loop counter/index -->
</readfile>
<set var="j" value="0" /> <!-- initialize write loop counter and array index to 0 -->
<while expression="[j] LT [i]" > <!-- stops at the number of lines read above -->
<!-- write out array variables, MathTest1out.txt will the same as MathTest1.txt, but the name and score
will be comma separated -->
<write file="MathTest1out.txt" string="[Name@[j]],[TestScore@[j]]{10}{13}" />
<math var="j" expression="[j]+1" /> <!-- increment loop counter/index -->
</while>
Notice that when referencing array variables in the write command above that both the array name and the index are in brackets and the index is also in brackets (e.g. [Name@[j]]). If not using a literal value for the index no square brackets are required (e.g. [Name@1]).
Be sure to look at the "ArrayTest" profile example include in the ComScript download.