Type buttons?
Blitz3D Forums/Blitz3D Beginners Area/Type buttons?
| ||
I am trying to make a game with kind of fancy windows style hud. I am using types for the buttons. I need some advise on how to do this the best way. Right now I am makeing nine buttons that will be used to ad energy taken from one of three user selected energy bars to compensate for damage done to the ships nine sections. Does that make sence? Here is the code so far. My main question is for buttons, am I better off using a for each next loop to create the nine buttons? Or should I continue the way I have started? Or should I abandon types and use data array? |
| ||
Well, you can't use a For-Each loop to CREATE (New) the type instances because they wouldn't exist yet. But you could go back and use a For-Each loop after you created all nine button instances. Personally, I would probably create an array of types and use Data statements to hold the initialization data. Something like this: Type buttons Field x Field y ;etc... End Type Dim repair.buttons(9) For iter = 1 To 9 repair(iter) = New buttons Read repair(iter)\x Read repair(iter)\y ;etc... Next Data 110, 300 ;etc... |
| ||
That's an excellently clear example of how to make Arrays of Types, Wolron! Thanks - something I've been a little scared of, but would find invaluable!!! |
| ||
I think you need a repair(iter)=New buttons in there. You can use array of type or just plain types - choice is yours. |
| ||
done |
| ||
Ya I think I will stick with plain types if they will work. I am still just getting the hang of using types. I'm like Mallice, array of types scare me, but I will experiment with them. What is the advantage to using an array of types? I'm sure they will make the code shorter, but can you do things like work on them as a whole? For instance in my if statment that asks if the mouse is over it, would I be able to just write one "If then" for all nine buttons? |
| ||
Do exactly what you were doing before :)For iter = 1 to 9 If ImagesOverlap (mousepoint,MouseX(),MouseY(),repair(iter)\image,repair(iter)\x,repair(iter)\y) ;do something EndIf Nextor... For thisbutton.buttons = Each buttons If ImagesOverlap (mousepoint,MouseX(),MouseY(),thisbutton\image,thisbutton\x,thisbutton\y) ;do something EndIf Next |
| ||
Well I said I would stick to normal types but now I think its unavoidable. Not for a button though, its for a ship rotation. I used the array of type code from above but I get "image does not exist". I think it is refering to the ship image, but I don't know why it whould say that. |
| ||
First of all, carier is spelled carrier :) At first glance, I can't see why. Run your program in debug mode and add more DebugLog statements to your program to find out what exactly is causing the error. |
| ||
I can,t believe it I forgot to put the carier(loop)=new carier in there. lol Thanks for your help. |