array/types

BlitzMax Forums/BlitzMax Beginners Area/array/types

If you create an array of types, you only create an array which can hold references to type-instances.
At each index, you need to use the NEW statement to create a new type-instance and put the pointer to that instance at the specified index.
Type test
	Field a:Int
	Field b:Int
End Type

' Create an array which can hold pointers to "test"-type-instances
' The indexes don't have a value yet, as you've not yet created any instances
local Ttest:test[10,10]


' Create instances for each index of the array and put their pointer inside the array
For i = 0 to 9
	For j = 0 to 9
		Ttest[i,j] = New test
	Next
Next

Print Ttest[1,1].a ' Should print "0", because an int field is initialised as "0"

Ttest[1,1].a=2 ' Set value
Print Ttest[1,1].a ' Print previously set value (should print "2")