ID:147620
 
I've read the guide and the reference entry, but I'm still having trouble with multidimensional lists. I'd like to define one that has a variable lenght, not a static length, so something like: groups[10][5] will not work for me.

I am using a proc to create this MDlist for another proc to reference. The purposes of this proc is to search through a list of players, sort them by the value of a particular variable they have on them, and then group them into the MDlist according to that value.

So, for example:

player1.color = red
player2.color = green
player3.color = blue
player4.color = yellow
player5.color = red
player6.color = green
player7.color = blue
player8.color = yellow

I would like the multidemensional list to be something like:

groups[red] = list(player1, player5)
etc...

Again, the number of colors and the number of players that could belong to each color are variable every time this proc is called, so I can't simply do groups[4][4].

This isn't my exact proc, because my exact proc is pretty garbled by now. This is what I would like to do with it, though.

The way I've tried to do it is first gather a list of all the colors that exist and put them into a temporary list, called temp. These colors are strings, of course. Then, I tried to make group[] = temp (the first dimension). Then, for each group, I ran through all the players in the area and if they had the right color, put them into group[color][index].

When the list is supposed to be converted into a string and displayed, nothing shows!

=$= Big J Money =$=


Here is an example, that will show you how you can manipulate multi-dimensional lists (I hope!).

var/list/MyList[][]
var/list/players = list("Bob"="Red","George"="Blue")
var/list/colors = list("Red","Blue")
proc/SortColors()
MyList = new()
for(var/c in colors)
MyList += c
MyList[c] = list()
// Added color. Now add players
world << "[c] added to MyList"
for(var/p in players)
var/col = players["[p]"]
if(MyList.Find(col))
var/A = MyList[col]
var/list/L = MyList[col][A]
L += p
MyList[col][A] = L

for(var/A in MyList)
world << "A = [A]"
var/B = MyList[A]
world << "B = [B]"
var/list/L = MyList[A][B]
world << "L = [L]"
for(var/i in L)
world << "[i] in L"