This site requires JavaScript, please enable it in your browser!
Greenfoot back
trash1000
trash1000 wrote ...

2012/5/1

Reset UserInfo highscores

trash1000 trash1000

2012/5/1

#
Hey, I just noticed there is something that I miss using UserInfo to store highscores from players: the function to reset highscores. Though you can download the data of UserInfo from the gallery I haven't seen a way to delete the data. However, it would come in handy e.g. when you changed the way points are calculated or other stuff.
Busch2207 Busch2207

2012/5/1

#
Well... I think that it was made on purpose that you can't clear the score so easily... I think, they want that we contrive ourselves something, that will do this...
trash1000 trash1000

2012/5/1

#
Well, I just checked the documentation for UserInfo and found a pretty easy way. The methods getNearby(int maxAmount) and getTop(int maxAmount) both return _all_ the data when maxAmount happens to be negative or zero. So a simple method resetting the highscore could look like this:
private UserInfo data;
private void resetHighscore() {
    if(UserInfo.isStorageAvailable()) {
        if(UserInfo.getMyInfo() != null) {
            data = UserInfo.getMyInfo();
            if(data.getUserName().equals("trash1000")) { // only when the creator of the scenario goes to the scenario it will reset the scores
               List<UserInfo> users = UserInfo.getTop(0);
               System.out.println(users.isEmpty());
               if(!users.isEmpty()) {
                   for(UserInfo u : users) {
                       u.setScore(0);
                       u.store();
                   }
               }
            }
        }
    }
}
Busch2207 Busch2207

2012/5/1

#
Well. I solved it similar! :) But I'd although add a key combination... ;)
trash1000 trash1000

2012/5/1

#
I did^^ I only check the user name to be mine in case someone figures out the key combo^^
nccb nccb

2012/5/1

#
It wasn't deliberate that we haven't added a way to add the high-scores... it's on our TODO list, we just haven't got to it yet! There will be a link on the website, available only to the scenario author, to wipe all data for that scenario.
You need to login to post a reply.