assign type to another - help
Blitz3D Forums/Blitz3D Beginners Area/assign type to another - help
| ||
I want a type that i can "assign" to another type when i create it. Say i'm making a gui and i have a window type which has some gadgets types assigned to it, it would be nice to just loop through the needed gadgets for this one window when i'm updating it. And maybe this will help to understand what i want: Type window Field x, y End Type Type gadget Field x, y End Type w.window = New window w\x = 32 w\y = 32 w.gadget = New gadget w\x = 24 w\y = 24Or something like that, i have no idea how to do this :/ |
| ||
Like this?Type window Field x, y Field g.gadget End Type Type gadget Field x, y End Type w.window = new window w\x = 32 w\y = 32 w\g = New gadget w\g\x = 24 w\g\x = 24 |
| ||
Yeh, well almost.Type window Field x, y Field g.gadget End Type Type gadget Field x, y End Type w.window = New window w\x = 32 w\y = 32 w\g = New gadget w\g\x = 24 w\g\y = 24 w.window = New window w\x = 32 w\y = 32 w\g = New gadget w\g\x = 24 w\g\y = 24 w\g = New gadget w\g\x = 24 w\g\y = 24 For w.window = Each window wc = wc + 1 gc = 0 For w\g = Each gadget gc = gc + 1 Next Next Print "window: "+wc Print "gadget: "+gc WaitKey End Result: window: 2 gadget: 3 I wanted the answer: window: 2 gadget: 2 But this helped me anyway so thanks! [edit]oh, i just thought of something that does what i wan't, i'll just try it out [edit2]didn't work, i'll just code it the way i usualy do |
| ||
Given a window type Type window Field x, y Field g.gadget End Type you could have a gadget type like this Type gadget Field x,y Field g.gadget End Type For new gadgets the gadget pointer in the gadget type is set to the existing window\gadget pointer. The gadget pointer in the window type is then set to point to the new gadget. So you build a chain of gadgets with new gadgets being being linked into the top of the list. Iterate through the gadgets for a window by following the gadget pointers until they are null. |
| ||
DJwoodgate: It sounds complicated, can you post an example? |
| ||
w.window = new window ; add a gadget to a window. g.gadget=new gadget g\g = w\g w\g = g ;..... ; iterate gadgets for a given window g.gadget = w\g while g<>null ; do gadget stuff g = g\g ; get next gadget (will be null if last gadget) wend |
| ||
Is this not more what you want?? |
| ||
Stevie G: Yeh, i tried that but i will probaly need loads of these windows and gadgets and it would be more code that way i think. DJWoodGate: That's exactly what i wanted, it works great! Thanks for everybodys help! |