- Home /
Implementing HighScore board
I'm wanting to implement a local Highscore board into my game and I'm not sure which is the best way to do this.
I've read a few posts about using PlayerPrefs to save the data and a few that say that creating a textfile to store the scores in would be better.
Which would be the best way?
Both ways seem valid, using PlayerPrefs does seem like a slightly simpler solution though.
You could for example save an array in your PlayerPrefs of all the highscores by using PlayerPrefsX.
I think reading the scores from a text file would probably require a bit of extra coding (maybe the text file would be a couple bytes smaller though?)
Personally, I'd serialize it in binary so that it's harder to edit by players. That would allow you to create/check a hash against a hash generator to check if it's been modified by the player.
Some useful tips to that end.
Couldn't you just as well encrypt the playerprefs values though?
Plus, it might not even be worth going through the hassle of encrypting the scores since it is only a local leader board.
@iwaldrop, quick question about the hash generation - Would you need to store one hashed and one non-hashed version of each value? And then each time you get the value you would generate a new hash from the non-hashed value and check it against the previously saved hash value?
So the logic would be something like:
if(GenerateNewHash(NonHashedValue) == HashedValue)
Sorry for the extra question.
Well, let me give you a for instance:
Two friends are competing in the same game, showing each other their leader-boards and motivating one another to do better...this actually happened between a group of my friends and Gradius V. Without having the score values protected from user tweaking, one could just go in, change their score to something higher, and win. Her other friends might give up, or play for a long time against an unachievable bar. I think it's comes down to just going that extra step to ensure that your products are 'tight'.
Saving the value in plain-text kind of defeats the purpose of serializing to binary in the first place. If someone actually went through the trouble of finding the scores in the binary file it would be a trivial matter for them to edit the plain text versions too. No, what you do is save the hash. Your code creates the hash and is, for all practical purposes, 'black-box'.
A quick search found John Skeet's answer to be quite good: link.
Thanks for the reply, think I will have to go over it again in the morning.
Not a topic for late in the evening ;)