Hi
Im an old time Blitz 3d user etc etc.
Coded quite a bit in the old days, but have now moved to Blitz Max
However I cannot get my head around the new OOp Structures with Types etc.
well I think I can get my head around it but one thing puzzles me.
Here is an example of some code (its not the complete code just the bits that seem to cause the problem)
Basically I have created a type for a list of menus.
this will hold quite a few menus, with locations (for when they pop up) headings and a few other details (I have cut most of the details out to make it simpler to view)
Problem is I create a new _list to store them in but it only seems to keep the last item I create.
I presume its because I have defined the _list globally somewhere and got it wrong and thus every time I call New() it has lost the last list and is starting from null
(hope that makes sense)
No doubt you fellas will suss out my stupidity quickly....I have spent the last 24 hours trying to get my head around what I have got wrong....other than that Im slowly getting to grips with types.
I know there are probably many better ways to do what I am doing, but I just want to understand the issue before I move on to dealing with the code in a better way....
Incidently the Text I write is just to find out how many entries are in the _list
I only ever get it coming back with 1 entry, and when I actually write the values it only contains the values, in this example, for Opt Menu
hopefully something simple, apologies for not working this out myself :)
I think the command -
May be causing me an issue, as I guess I may need to actually define this when creating it so that it becomes menulists_list but not sure how to explain that
Kind regards,
Mark
Im an old time Blitz 3d user etc etc.
Coded quite a bit in the old days, but have now moved to Blitz Max
However I cannot get my head around the new OOp Structures with Types etc.
well I think I can get my head around it but one thing puzzles me.
Here is an example of some code (its not the complete code just the bits that seem to cause the problem)
Basically I have created a type for a list of menus.
this will hold quite a few menus, with locations (for when they pop up) headings and a few other details (I have cut most of the details out to make it simpler to view)
Problem is I create a new _list to store them in but it only seems to keep the last item I create.
I presume its because I have defined the _list globally somewhere and got it wrong and thus every time I call New() it has lost the last list and is starting from null
(hope that makes sense)
No doubt you fellas will suss out my stupidity quickly....I have spent the last 24 hours trying to get my head around what I have got wrong....other than that Im slowly getting to grips with types.
I know there are probably many better ways to do what I am doing, but I just want to understand the issue before I move on to dealing with the code in a better way....
Strict ' Constants Const WIDTH = 1024, HEIGHT = 800, DEPTH = 32, HERTZ=60 ' Menu Constants ' Globals Global total_menus Global _list:TList Type MenuLists Field id Field x# Field y# Field title$ Field items$[10] Field totalitem Method New() If _list = Null _list = New TList EndIf _list.addlast(Self) EndMethod Method DrawMenuOpen() ' some rubbish code here EndMethod End Type Init() createMenus() MainLoop() End Function Init() SetGraphicsDriver(GLMax2DDriver()) Graphics WIDTH, HEIGHT, DEPTH, HERTZ End Function Function MainLoop() While Not AppTerminate() And Not KeyHit(KEY_ESCAPE) Update() Wend End Function Function Update() SetBlend SOLIDBLEND SetAlpha(1) SetClsColor(255, 255, 255) Cls Local MenuL:menulists Local Counter For MenuL = EachIn _list Counter = Counter + 1 DrawText(Counter,100,20 + (counter*20)) Next Flip() End Function Function createMenus() Local xx,zz RestoreData menu_data ReadData total_menus For xx = 1 To total_menus Global M:MenuLists = New MenuLists ReadData M.Id ReadData M.Title$ ReadData M.totalitem ReadData M.x# ReadData M.y# For zz = 1 To m.totalitem ReadData M.items$[zz] Next Next End Function ' Data details - Menu id, LocationX#, LocationY#, Heading, Total Links, link list...... #menu_data DefData 3 DefData 1, "Main Menu", 5, 300, 780, "Main Menu Item 1", "Main Menu Item 2", "Main Menu Item 3", "Main Menu Item 4", "Main Menu Item 5" DefData 2, "Sub Menu", 5, 500, 780, "Sub Menu Item 1", "Sub Menu Item 2", "Sub Menu Item 3", "Sub Menu Item 4", "Sub Menu Item 5" DefData 3, "Opt Menu", 4, 700, 780, "Opt Menu Item 1", "Opt Menu Item 2", "Opt Menu Item 3"
Incidently the Text I write is just to find out how many entries are in the _list
I only ever get it coming back with 1 entry, and when I actually write the values it only contains the values, in this example, for Opt Menu
hopefully something simple, apologies for not working this out myself :)
I think the command -
Global _list:TList
May be causing me an issue, as I guess I may need to actually define this when creating it so that it becomes menulists_list but not sure how to explain that
Kind regards,
Mark