array of lists
BlitzMax Forums/BlitzMax Programming/array of lists
| ||
I need an array of lists OR a map of lists e.g. global map_square_item_list:tlist(50,50) but it keeps saying it cant reference it when I try to add a type to one of the lists so, how would I create an array of lists and add a type instance to the list? |
| ||
Blitzmax arrays use square brackets. Also, make sure you loop through the array and initialize each new list before you use it -- otherwise you'll be adding objects to null lists. This should work: Global mapList:TList[50,50] For Local x:Int = 0 To 49 For Local y:Int = 0 To 49 mapList[x,y] = CreateList() Next Next |
| ||
What are you *really* trying to do? Do you really want a 50 by 50 array for lists? It really makes things easier if you post the code you're having problems wit. Here is a simple example : Local array_of_lists:TList[2] Local list1:TList=CreateList() list1.addlast("1") list1.addlast("2") list1.addlast("3") Local list2:TList=CreateList() list2.addlast("7") list2.addlast("8") list2.addlast("9") array_of_lists[0]=list1 array_of_lists[1]=list2 For Local x:Int=0 To 1 For Local all:String=EachIn array_of_lists[x] Print all Next Next <edit> Arrggghh you edited your post. |
| ||
thanks all, I got it working now |
| ||
Don't know what you're doing but if you're doing a tile/grid based game, then instead of having seperate arrays of lists like items[x,y] enemies[x,y] etc try making a cell or square type, having these lists as a field and an update/draw method. It might make things better organised. I can give an example if you like. |
| ||
i used arrays to help with pathfinding speed, thanks for the help |