4
\$\begingroup\$

I want to delete the preferences that saved my last highscore. How can I do this?

Here's how I am saving preferences at the moment:

prefs = Gdx.app.getPreferences("ZombieBird");
if (!prefs.contains("highScore")){
    prefs.putInteger("highScore", 0);
}

public static void setHighScore(int val) {
   prefs.putInteger("highScore", val);
   prefs.flush();
}
\$\endgroup\$
5
  • \$\begingroup\$ How do you make what? How did you save your preferences? This question is pretty much unanswerable in it's current form \$\endgroup\$
    – Elva
    Oct 14, 2015 at 13:40
  • \$\begingroup\$ No.I have highscore ,I want to reset it.To do that I must delete all preferences that are saving my highscore.I dont know how to do that \$\endgroup\$ Oct 14, 2015 at 13:45
  • \$\begingroup\$ Okay, delete the file in which the preferences are stored. How do you do that? No one knows because you haven't stated what you are using to save preferences. \$\endgroup\$
    – Elva
    Oct 14, 2015 at 13:48
  • \$\begingroup\$ prefs = Gdx.app.getPreferences("ZombieBird"); if (!prefs.contains("highScore")){ prefs.putInteger("highScore", 0); } } public static void setHighScore(int val) { prefs.putInteger("highScore", val); prefs.flush(); } \$\endgroup\$ Oct 14, 2015 at 13:59
  • \$\begingroup\$ On Android, perhaps you're looking for SharedPreferences.Editor::clear? \$\endgroup\$
    – Anko
    Oct 14, 2015 at 21:03

3 Answers 3

8
\$\begingroup\$

To delete preferences data—

Manually

On desktop, shared preferences data is in User/.prefs. Simply delete the files in it.

On Android, do App InfoClear data.

Programmatically (Android and Desktop)

If you change the Key (string) of your sharedpreferece you will lose your data. To do this, use

prefs.putInteger("keyString", newValue)
\$\endgroup\$
2
  • \$\begingroup\$ were I can find the ""app info""" (i work in eclipse() \$\endgroup\$ Oct 14, 2015 at 14:33
  • \$\begingroup\$ He means on your android phone. The preferences are linked to the game internally and you cannot influence it with eclipse other then by writing code. \$\endgroup\$
    – Madmenyo
    Oct 16, 2015 at 8:52
4
\$\begingroup\$

To do it programmatically without having to keep track of all the keys:

Preferences prefs = Gdx.app.getPreferences( "your_preferences_name_here" );

// Clears the values
prefs.clear();

// Saves the change
prefs.flush();
\$\endgroup\$
1
\$\begingroup\$

Just for the Mac to delete preferences/data you need to go to:

~/.prefs

and delete you game file.

https://github.com/libgdx/libgdx/wiki/Preferences#storage

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .