Having difficulty with Arrays of Types...

Blitz3D Forums/Blitz3D Beginners Area/Having difficulty with Arrays of Types...

You can try this:

; Create a type which holds the x, y and z values
Type t_unit_loc
Field x,y,z
End Type

; Create an array of types
; Note that the array holds the memory-address of the types,
; so you will have to create all type-instances and put the
; handle of that type in the array
Dim Unit1.t_unit_loc(5)

; Create 5 type-instances and put the handle in the array
For i = 1 to 5
Unit1.t_unit_loc(i) = New t_unit_loc
Next

; After this, you can refer to the variables in the array
; this way:
Unit1(1)\x = 55
Unit1(2)\y = 10
Unit1(5)\z = 159

; Print the contents of the array

For i = 1 to 5
Print Unit1(i)\x
Print Unit1(i)\y
Print Unit1(i)\z
Print ""
Next

WaitKey()


Note that this example creates only 1 array called "Unit1",
it holds the handles (memory-addresses) of the types "t_unit_loc",
and has 5 indexes.

When the printout comes, you see the data in the entire array.
Each block of three lines displays the x,y and z values of each index (you can see that there are 5).
Actually the array has 6 indexes (0-5), but I haven't used index 0.