Reputation: 203
When i have tested my game on desktop the prefs work perfectly and correct scores and highscore is output but when i run it on mobile the values do not save and for both scores show 0. There is no errors also. Just need some help to try and fix this. Thanks alex.
pref = Gdx.app.getPreferences("Scores");
if(pref.contains("Score") == false) {
pref.putInteger("Score", 0);
if(pref.contains("HighScore") == false){
pref.putInteger("HighScore", 0);
}
}
GameOver Screen
pref = Gdx.app.getPreferences("Scores");
score = pref.getInteger("Score");
highScore = pref.getInteger("HighScore");
if(score > highScore){
pref.putInteger("HighScore", score);
highScore = score;
}
This is ran when the player dies.
public void updateScore(){
if (pref.contains("Score") == true){
}
pref.putInteger("Score", hud.getScore());
}
Upvotes: 0
Views: 413
Reputation: 13571
You need to call flush()
method after putting a value to preferences - it causes commiting data to the memory
pref.putInteger("Score", hud.getScore()).flush();
The a look at official wiki also
Upvotes: 2