ID:160364
 
I am trying to make a scoreboard that saves peoples top score in order from highest to lowest. Just like the image below.



Things I need to know:
1. How to actually get the score to save onto a scoreboard
2. How to get the top 100 in order from highest to lowest
3. How to make it change a person say from 1st to 2nd if he/she gets beat

Please don't give me a link to a library of a scoreboard. If you post code, only do daft little snippets that would show me how it's done. If you just give me the whole code, I wouldn't learn anything from copying and pasting.
Here is one (somewhat messily commented) example of how to do it: [link]

What I did there was use an associative list, removing the entry of the person if they were already there and checking where to insert the entry based on other people's scores.

So to answer your questions based on the examples of [link]:

1. The example uses an associative list to enter the score data (and two procedures to load/save it).

2. Already explained in the 2nd (or 1st big) paragraph.

3. This is done in the example by removing the persons data for cases like this.

Note that the example is not the top 100, to do that:
//  lets say we have a top 25:
if(!highscore.len) // making sure that there is some entry in the high score table.
Ref << "No one was good enough to be on the highscore list!"
else // If the above check wasn't there, the following line would give an error - I assume anyways - due to for(1 to 0)
for(var/i=1 to min(25,highscore.len)) // From entry #1 - the highscore's entry length (upto 25 maximum).
Ref << "#[i]: [highscore[highscore[i]][1]] - [highscore[highscore[i]][2]]"
// The above outputs the following: "#[position] [1st entry in the highscore of the entry, which is the name] - [2nd entry in the highscore of the entry, which is the score]"
1. How to actually get the score to save onto a scoreboard
2. How to get the top 100 in order from highest to lowest
3. How to make it change a person say from 1st to 2nd if he/she gets beat

1) This is where lists, indexes, and associations are useful. Scoreboard = one huge list, ordered by score. I'll just use text strings rather than 2 text strings and list; you have to do a little parsing, but it's infinitely better (resource wise).

2 and 3) Sort them by index:

var/list/HS[100] //create a new list, with a len of 100

//Someone please correct me if I'm wrong, but the findtext()
//proc returns the position of the last piece of text in a string
//right? If I'm wrong, it should be B = blah+3 rather than 1

//EDIT: Fixed it; now it uses 3

proc/find_score(I) //I for index num
if(!(istext(HS[I]))) return //don't want errors
var/B = findtext(HS[I]," - ")+3 //B for beginning
return text2num(copytext(HS[I],B))

proc/Add_Highscore(score,name)
var/F = HS.Find(null)
if(F) //if there is something null in the list (no score)
HS[F] = "[name] - [score]"
else
if(score > find_score(100))
HS[100] = "[name] - [score]"
Sort_Highscores() //this would be your sorting algorithm


EDIT: Did I mention Air Mapster (Mike H) or Airjoe or someone like that has a DMCGI scoreboard demo?
In response to Jeff8500
Make sure players can't have " - " in their name.
In response to Jeff8500
findtext() returns the position of the beginning of the word if found; 0 otherwise.
In response to Jemai1
I'll fix it, then.