Basic Arrays
An array holds many values under one name, each picked out by a number called its index. Make one with Dim, giving the highest index:
Dim scores(10) ; scores(0) to scores(10): 11 valuesscores(1) = 500scores(2) = scores(1) + 50For i = 0 To 10 Print i + ": " + scores(i)Next
Indexes start at 0, and the number given to Dim is the highest, so Dim scores(10) holds 11 values. Using an index outside that range stops the program with an error, rather than quietly reading or writing the wrong thing. Every element starts at 0, 0.0, an empty string or Null.
Types and grids
A type tag on the name sets what the array holds: Dim speeds#(5), Dim names$(5) or Dim fleet.Ship(20). Give more than one size for a grid, such as a map of tiles:
Dim map(31, 23) ; 32 across by 24 downmap(5, 10) = 1 ; a wall
Where arrays can be used
Arrays made with Dim belong to the whole program: the main program and every function can use them. Using Dim again on the same array makes it afresh, at the new size, with every element back to empty; this is how to resize one, or clear it in one go.
Fixed-size arrays
A one-dimensional array can also be declared with square brackets, in a Local, Global or Field statement. Its size is fixed when the program is written, and like other variables it belongs to where it is declared. As a Field, it gives every object of a type its own row of values:
Type Player Field name$ Field lapTimes#[2] ; lapTimes[0] to lapTimes[2]End TypeLocal seen[5]seen[3] = 1
