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=0; temp.i<temp.board.size(); temp.i++) {
temp.acc = temp.board[temp.i];
temp.score = temp.board[temp.i].score;
echo(temp.i+1 @". "@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
|