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

2021/6/22

i want top score ,i used static variable to store problem

venkatesh438 venkatesh438

2021/6/22

#
i want top score ,i used static variable to store it but when i closed application and reopen entire application values top score starts from 0 .but i want my past top score .please help me....
RcCookie RcCookie

2021/6/22

#
Static variables are only stored during a JVM session, which is restarted even if you hit „reset“. You can use the UserInfo class for this:
public static void updateScore(int score) {
    if(UserInfo.isStorageAvailable()) {
        System.err.printLn(„No storage available“);
        return;
    }
    UserInfo user = UserInfo.getMyInfo();
    if(user.getScore() >= score)
        return; // No new highscore, so don’t update it
    user.setScore(score);
    user.store();
}

public void getHigh() {
    UserInfo user = UserInfo.getMyInfo();
    return user != null ? user.getScore() : 0;
}
venkatesh438 venkatesh438

2021/6/23

#
thanks bro
You need to login to post a reply.