ID:154219
 
I keep having a problem with lists. I think its more in the complex ways I'm trying to use them

Here is what I'm trying to do right now. I'm setting up the list not attaching it to anything like mob/ world/ etc..

var/list/hs[20][]

What I need is a list 20 slots long. Into this I will need to store 2 things, 1) Name & 2) Score. This is be the list I save
as a savefile.

My complex problem comes to this. I need to create a way to cycle through everyone in the client in the game once ever minute. During this cycle all the scores and names need to be added to a temp list. Somehow I need to list to sort by score, with the person with the highest score being in slot 1 of list/hs along with the name that goes with that score. The savefile part won't be too hard once I can get this working. Anyone who can help me on this gets a 1 month Subscription to Star Traders.

Thanks,
LJR
You're in luck! Here's a bit of code from my high score library, which is due out sometime this decade... Hopefully this'll be something like what you wanted.
score
var/score = 0
var/name = ""

proc/SortScores(list/s)
if (istype(s))
for (var/i = 1; i < s.len; i++)
var/score/si = s[i]
for (var/j = i+1; j <= s.len; j++)
var/score/sj = s[j]
// if scores are identical, also sort alphabetically by name
if ((si.score < sj.score) || ((si.score == sj.score) && (sorttext(si.name, sj.name) < 0)))
var/t = s[i]
s[i] = s[j]
s[j] = t
si = sj
sj = t


proc/GetAllScores()
var/list/hs[0]
for (var/mob/m in world)
if (m.client)
var/score/s = new
s.score = m.score
s.name = m.name
hs += s
SortScores(hs)