Arrays
You can imagine an array as a list of variables combined together in a unique entity. Arrays are created using the dim command by specifying its name and the number of elements (variables) the array will contain.
For example:
dim list[4]
The above example create an array entity of five empty elements: (0, 0, 0, 0, 0) with index from 0 to 4 because by default, sdlBasic arrays begin with index 0 and not 1.
Note that sdlBasic use square brackets [ ] instead of round brackets ( ) in arrays definition.
In order to access an element in the array you must type the array name followed by the index number between square brackets.
For example:
list[2]=10
print list[3]
Arrays can be mono-dimensional, like the above examples, or multidimensional. Imagine this kind of array as an array of arrays. Multidimensional array are defined by a series of indexes separated by commas.
For example:
dim list[2, 3]
The above example create bi-dimensional array entity of three arrays containing four empty elements:
((0, 0, 0, 0),(0, 0, 0, 0),(0, 0, 0, 0),(0, 0, 0, 0))
In order to access a specific value in multidimensional array, you simply type it's name followed by the list of indexes separated by commas and between square brackets.
For example:
list[2, 3]=10
print list[1, 2]