var/list/Test=list("Guy1"=200,"Guy2" = 100,"Guy3" = 300)
ID:164276
Jul 1 2007, 4:21 pm
|
|
Could anyone give me a example on how to sort associative lists? I would like to have a list like this put in order buy the highest value. Also how can I return the name of the first person in the list? I tried doing something like this Test[1], but I just get a index out of bounds runtime. Thanks for the help
|
Jul 1 2007, 5:26 pm
|
|
check my members page, and on the left there is a list sorting demo or lib i forget
|
In response to Xx Dark Wizard xX
|
|
Xx Dark Wizard xX wrote:
check my members page, and on the left there is a list sorting demo or lib i forget I tried passing my list through all three list procs and none would sort the list by there numerical value. What I am trying to is not put them in alphabetical order but put them in order like this example Guy3 Guy1 Guy2 var/list/Test=list("Guy1"=200,"Guy2" = 100,"Guy3" = 300) |
In response to Brokenleg
|
|
Hmmm. That lemme go look at it.
|
In response to Brokenleg
|
|
Use this to display the list,
proc/list2text(list[]) |
In response to Xx Dark Wizard xX
|
|
In response to Brokenleg
|
|
Do you want it backwards then, or to sort by comparing the associated value.
|
In response to Xx Dark Wizard xX
|
|
Xx Dark Wizard xX wrote:
Do you want it backwards then, or to sort by comparing the associated value. yeah, by there associated value like this. Guy3 = 300 Guy1 = 200 Guy2 = 100 Edit* basically this is just a list that will put players in order by how much hate they have generated towards this monster with this list. Then the person in the first spot will be its target. |
In response to Brokenleg
|
|
I guess I could write a proc for ya, just tell me if it works :)
proc/Sort(list/L) |
In response to Xx Dark Wizard xX
|
|
Sweet, it works like a charm thanks alot. I didn't realize you could access the associative list values like this L[L[j]].
|
In response to Brokenleg
|
|
L[L[i]] actually gets L[i] which could be the text string and access it in L you can also get the value with L["player"], glad it works.
|