array/types
BlitzMax Forums/BlitzMax Beginners Area/array/types
| ||
Since I am converting my list over to arrays. I was wondering can you set an array to a type such as this: type test Field a:Int Field b:Int End Type Ttest:test[10,10] can could you access it buy doing the following: print Ttest[1,1].a now when I put an item into the array it doesn't do what I expect. Ttest[1,1].a=2 makes every single a field 2. Is there some way for me to have this kinda of access, do I just have the syntax wrong? Thanks in advance |
| ||
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") |
| ||
WOw thanks for the speedy responce. Still working on getting my head around the type-instances. But I think I understand how it works now. Thanks TwistedCube |