Lists of Lists? Arrays of Lists?
BlitzMax Forums/BlitzMax Beginners Area/Lists of Lists? Arrays of Lists?
| ||
Hi, I'm a little bit of a crossroads and wondered if anyone couldgive me some advice. I need to store several lists of objects. Each list could contain a different number of objects and the number of lists I need to create and maintain will also fluctuate depending on the game state. So basically I need a mechanism by which I can create and access a varying number of lists. I wondered what the best way to do this is - can you have a lists of lists? Or an array of lists? Has anyone done this before and could give me the benefit of their experience? Thanks in advance. |
| ||
I think list of lists would be good. Quick (and perhaps rubbish) example mylist1:tlist=CreateList() mylist2:tlist=CreateList() mylist3:tlist=CreateList() ListAddLast(mylist2,"one") ListAddLast(mylist2,"two") ListAddLast(mylist2,"three") ListAddLast(mylist3,"four") ListAddLast(mylist3,"five") ListAddLast(mylist1,mylist2) ListAddLast(mylist1,mylist3) For Local t:tlist=EachIn mylist1 For x$ = EachIn t Print x Next Next |
| ||
Since a TList is just an Object like any other, you can create as you say, lists of lists, arrays of lists, and even maps of lists (which I find quite handy) Here's how I use TMap and TList (a map containing several lists). Each list is stored in the TMap using a key string, like "win" for a list of windows, "but" for a list of buttons, etc. ' The map Local controls:TMap = new TMap ' add a list for the type "win" controls.insert("win", new TList) ' and one for "but" controls.insert("but", new TList) ' The map now contains 2 separate lists. ' Retrieve the "win" list Local list:TList = TList(controls.valueForKey("win")) It's just an example, and one which I find very useful for tracking specific kinds of lists... |
| ||
OK guys, thanks for the tips. Brucey - TMap? What is it? Cant find any reference to it in the docs? |
| ||
tmap wiki tmap |