Thread: Scoreboard
View Single Post
  #2  
Old 11-15-2014, 01:47 PM
BlueMelon BlueMelon is offline
asdfg
BlueMelon's Avatar
Join Date: Sep 2008
Posts: 1,481
BlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to behold
Basically what you want to do is create a sorted array?

Look into the sortByValue function.

Quote:
TGraalVar.sortbyvalue(str, str, bool) - sorts an array, specify the variable of the array members which is compared, also the variable type and if it should be sorted ascending; variable type can be "string", otherwise it is sorted by floating point value
Example:
PHP Code:
function onCreated() {

  
temp.plScores = {
    {
"BlueMelon",9001},
    {
"snk",69},
    {
"BigMonster",1337},
    {
"supaman771",7331}
  };

  
temp.board null;
  for(
temp.plScore temp.plScores) {
    
temp.board.add(temp.plScore[0]); // acc
    
temp.board[temp.board.size() - 1].score temp.plScore[1]; // score
  
}

  
temp.board.sortByValue("score""float"false);

  echo(
"Scoreboard: ");
  for(
temp.i=0temp.i<temp.board.size(); temp.i++) {
    
temp.acc temp.board[temp.i];
    
temp.score temp.board[temp.i].score;
    echo(
temp.i+@". "@temp.acc SPC "with" SPC temp.score);
  }

which gives
Quote:
Scoreboard:
1. BlueMelon with 9001
2. supaman771 with 7331
3. BigMonster with 1337
4. snk with 69
__________________
http://i.imgur.com/OOJbW.jpg
Reply With Quote