if (count > PlayerPrefs.GetInt(“Score1”)){
PlayerPrefs.SetInt(“Score2”, PlayerPrefs.GetInt(“Score1”));
PlayerPrefs.SetInt(“Score1”, count);
}
else if (count > PlayerPrefs.GetInt(“Score2”)){
PlayerPrefs.SetInt(“Score3”, PlayerPrefs.GetInt(“Score2”));
PlayerPrefs.SetInt(“Score2”, count);
}
else if (count > PlayerPrefs.GetInt(“Score3”)){
PlayerPrefs.SetInt(“Score4”, PlayerPrefs.GetInt(“Score3”));
PlayerPrefs.SetInt(“Score3”, count);
}
else if (count > PlayerPrefs.GetInt(“Score4”)){
PlayerPrefs.SetInt(“Score5”, PlayerPrefs.GetInt(“Score4”));
PlayerPrefs.SetInt(“Score4”, count);
}
else if (count > PlayerPrefs.GetInt(“Score5”)){
PlayerPrefs.SetInt(“Score6”, PlayerPrefs.GetInt(“Score5”));
PlayerPrefs.SetInt(“Score5”, count);
}
else if (count > PlayerPrefs.GetInt(“Score6”)){
PlayerPrefs.SetInt(“Score7”, PlayerPrefs.GetInt(“Score6”));
PlayerPrefs.SetInt(“Score6”, count);
}
else if (count > PlayerPrefs.GetInt(“Score7”)){
PlayerPrefs.SetInt(“Score8”, PlayerPrefs.GetInt(“Score7”));
PlayerPrefs.SetInt(“Score7”, count);
}
else if (count > PlayerPrefs.GetInt(“Score8”)){
PlayerPrefs.SetInt(“Score9”, PlayerPrefs.GetInt(“Score8”));
PlayerPrefs.SetInt(“Score8”, count);
}
else if (count > PlayerPrefs.GetInt(“Score9”)){
PlayerPrefs.SetInt(“Score10”, PlayerPrefs.GetInt(“Score9”));
PlayerPrefs.SetInt(“Score9”, count);
}
else if (count > PlayerPrefs.GetInt(“Score10”)){
PlayerPrefs.SetInt(“Score11”, PlayerPrefs.GetInt(“Score10”));
PlayerPrefs.SetInt(“Score10”, count);
}
So I want it to update for when the count is higher than the already set highscore, but to do that I would need to make the high score pass down to the score below it, but then I’d need to do that for every score below it as well. How can I recode this to make this easily implemented? Cause the way I have it now only passes the score you beat down. *say you score #2 highest score, your old #2 score passes down to #3 and then the old #3 score is just replaced but isn’t passed down as #4.
Thanks.
It seems like you are on the right track already with the initial replacements, now you just need to do the rest.
Depending on how many high scores you are trying to store you could just do the exact ones right there in those else ifs you already have.
Ideally you would just set up a function which receives the high score you set to know what to do.
For Example:
else if (count > PlayerPrefs.GetInt("Score3")){
PlayerPrefs.SetInt("Score4", PlayerPrefs.GetInt("Score3"));
PlayerPrefs.SetInt("Score3", count);
//send this function with the high score you just set in this case #3
int highScoreRank = 3;
setRemainingHighScoresFunction(highScoreRank);
}
//calls this function
void setRemainingHighScoresFunction(int newHighScoreRank)
{
//get the scores
int oldScore;
int newScore;
//so for example if you want to record the top 10 it would be
int highestRecordedRank = 10;
for (int i = newHighScoreRank; i < highestRecordedRank - 1; ++i)
{
//previous rank possibilities
//example starting spot
else if (int i == 3)
{
oldScore = PlayerPrefs.GetInt("Score4");
//if score does not tie
if (newScore != oldScore)
{
PlayerPrefs.SetInt("Score5", oldScore);
newScore = oldScore;
}
//if you don't want duplicate scores entries for adjacent high scores you would return here
else return;
//if you do want duplicate score entries this example is a little goofed up my bad
}
//do rest of possibilities for example:
//else if (int i == 4)
}
I’m not really willing to double check any of that logic at the moment, and I’ve been getting into my beer programming stage for the night. So I would not be surprised one bit if there are errors with the specifics. But that should hopefully help you a little to get started.
Hmm not sure if you want to record duplicate scores of the same value as high scores, that might be a mistake in this example so you could just remove the part:
if (newScore != oldScore)
{
Also with this example if you don’t want duplicate scores you would need to do the first
if (newScore != oldScore)
{
BEFORE you call the function since the first comparison in this example could not detect it correctly.