More TYPE nonsense
Blitz3D Forums/Blitz3D Beginners Area/More TYPE nonsense
| ||
I've been through the tutorials for using TYPEs, I just wanted to check something. Say I create a type: TYPE thing field x field y End Type And then I want to create a number of them, I can loop: For i = 1 to 5 group.thing = New thing Next And if I want to access them, I have to loop through them: For group.thing = each thing group\x = group\x + 1 Next What I don't seem to be able to do is create an array of "thing" and access each one directly. In C I would just: struct MYTHING { float x; float y; } thing[100]; And access each one directly. . . thing[36].x = 4.0; etc Is this not possible with types in BlitzPlus? |
| ||
Dim group.thing( 100 ) group( 0 )\x = 10 group( 2 )\y = 15 |
| ||
Thanks. . . I was sure I'd tried that and failed. Need more caffine :) |
| ||
I think this works as well: type blah field a end type type blah2 field b.blah[10] end type Btw, square parentheses are neccessary for arrays in types, and said arrays can only be one dimensional, but that doesn't stop you from indexing them like so: y*10 + x |
| ||
On second thoughts, this isn't working: Type thing Field x End Type Dim group.thing(100) group(1)\x = 4 This just gives me an error. . . "Object does not exist" (Debugger pointing to the group(1)\x = 4 line) Do they have to be initialised in some way maybe? |
| ||
sswift's method is working, that'll do for me :) Thanks guys |
| ||
You need to create it with new first:Type thing Field x End Type Dim group.thing(100) group.thing(1)=New thing group(1)\x = 4 Bye.. |
| ||
As Tiger pointed to... Dim group.thing(100) just creates an array that CAN store the pointers to 100 things. The memory for each thing still needs to be allocated with New. |
| ||
Yeah, sorry forgot that bit - just assumed you'd know. |
| ||
"sswift's method is working, that'll do for me :) Thanks guys" Without using NEW? That migth be a bug... The array is just supposed to be pointers to types, not create new types itself. |
| ||
No, I did use New. I am new at this, I've done nothing but code C for the past year so it's hard to shake off bad habbits. To be honest so much code has passed I can hardly remember what I tried for the other method now. In any case, all's fine. |
| ||
Type thing Field x End Type Dim group.thing(100) ; Create the instances and fill the array with the pointers to those instances For i = 0 to 100 group(i) = New thing Next group(1)\x = 4 |