Help with arrays

BlitzPlus Forums/BlitzPlus Programming/Help with arrays

The Forum Archive is locked. These are the original blitzbasic.com forums, kept so their posts can still be read and searched. No new topics, replies or edits can be made here. To join the conversation, head over to the Blitz3D+ forums.

Normally, you could have a single variable called for instance DataX:
DataX = 1

With arrays, you can enumerate this variable:
Dim DataX(3)

DataX(0) = 1
DataX(1) = 999
DataX(2) = 34
DataX(3) = 123

You could do this instead:
DataX0 = 1
DataX1 = 999
DataX2 = 34
DataX3 = 123

It would do the same, however, with a 'Dim' array, you can use another variable as the index:
p = 1
DataX(p) = 999


With a For..Next loop, the program loops a variable between a start and an end value
For p = 0 to 3
print p
Next

So, combine those two methods and you can fill an array with numbers:
Dim DataX(3)
For p = 0 to 3
DataX(p) = 999
Next

for p = 0 to 3
Print "DataX("+p+") = " + DataX(p)
next

Types are a more advanced method of storing/looping through data. However 'Dim' arrays are a standard feature of Basic languages and in some situations, they could come in handy.