Hi Guys
First of all Im a bit of a beginner when it comes to scripting so sorry if this is obvious.
I bought a little unity script that displays a highscore table, Ive implemented it and all is fine but I need it to sort and display the hiscores inverted, ie instead of displaying the scores in descending order, I need it to display ascending with negative scores at the top, for example:
- blahblah -10
- blahlahh -8
- blahlala 6
- blahaha 15
Although I cant show the code here, its pretty much exactly the same as the code in this thread:
http://forum.unity3d.com/threads/24031-Local-Highscores?highlight=high+score
Can anyone give me any suggestions as to what I need to do? Ive tried pretty much everything but as Im starting out Im not exactly sure of the logic involved…
Id really appreciate any help, as this is the last thing Ive got to do and my little game is finished!
You will have to make a change to the script. in InsertEntry
if (entry.score < entries[i].score || entries[i].score == 0.0) {
entries.Insert (i, entry);
break;
}
if you change this to
if (entry.score > entries[i].score || entries[i].score == 0.0) {
entries.Insert (i, entry);
break;
}
you should be oke. Just clear the database.
If you like you can also make a sort function that goes through all entries placing them in the correct order.
Hi thanks for your suggestion, but unfortunately it didn’t work - I also tried that previousley…
any other ideas?
Afaik, it should work, unless you sort the list somewhere else as well. Try debugging with some Debug.Log()'s to see at what index the entry is inserted and see if that is correct.
you also said you wanted to support negative scores. You need to remove the or( || ) statement in the if check.
if (entry.score > entries[i].score) {
entries.Insert (i, entry);
break;
}
Also I don’t know what way you’re reading the scores to dispaly, but that is going to put higher numbers in the front of the array(lower subs). So maybe you needed to keep it like:
if (entry.score < entries[i].score) {
entries.Insert (i, entry);
break;
}
Hi guys
Thanks for the help, I got it working eventually - was similar to what you guys said just in a different way so thanks 