TYPE help wtd
Blitz3D Forums/Blitz3D Beginners Area/TYPE help wtd
| ||
If i have a type ie type box field x field y end type and i wanted to create 5 new boxes box1.box=new box box1\x=5 box1\y=10 etc for the other 4, how can i create a loop so that i can create all 5 with minimum code. Is this possible bearing in mind that each name must be unique? thanks |
| ||
Use an array - something like this (untested):Dim Box.tBox(4) For N = 0 to 4 Box(N) = New tBox Box(N)\x = 5 Box(N)\y = 10 Next Type tBox Field X Field Y End Type |
| ||
Hey, remember the box1.box is just a variable. It doesn't really name the type in anyway. You could have 5 different handles pointing to the same type object:Type box Field x,y End Type b.box = new box b1.box = b.box b2.box = b.box etc etc Following on from that, you can just create five boxes in a loop, then assign the handles to an array, or five different variable. Type box Field x,y End Type dim box_handle(5) For loop = 1 to 5 b.box = new box b\x = 5 b\y = 10 box_handle(loop) = handle (b.box) ; store the type objects handle, in an array Next ; all of the types have a unique handle, stored in the box_handle() array. To access the 4th one say, you would find the object by doing... b.box = Object.box(box_handle(4)) print b\x |
| ||
Ross, I've never seen the 'handle' & 'object' commands before. I think they could be very usefull. They are not in the manual; so how do you find out about them? Is there any documentation on them somewhere? Thanks Marg |
| ||
Yes it is interesting, but I also checked the manual and I think he is just using them as "variable names". The only commands with the term "handle" are the one that choose the origin or starting point of images or sprites. |
| ||
Someone else posted around here. There very useful for things, but just remember, since they are undocumented, they could be removed in future versions of blitz, without notice :o) But, for the task at hand, i think Gfk's way is alot better and easier. Handle command basically gets the pointer information of that type object. box = Handle (b.box) box now contains the handle information for that object. Return to the type object by using the object command. Saves you cycling through all the type objects, to search for that one again. |