Scripting 5.6. Arrays

You can use arrays of numeric and string variables:

for i from 1 to 5
    square [i] = i * i
    text$ [i] = mid$ ("hello", i)

After this, the variables square[1], square[2], square[3], square[4], square[5], text$[1], text$[2], text$[3], text$[4], and text$[5] contain the values 1, 4, 9, 16, 25, "h", "e", "l", "l", and "o", respectively:

writeInfoLine: "Some squares:"
for i from 1 to 5
    appendInfoLine: "The square of ", i, " is ", square [i]

You can use any number of variables in a script, but you can also use Matrix or Sound objects for arrays.

Links to this page

© ppgb, January 11, 2014