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

2018/9/13

How can I save and read a highscore?

1
2
danpost danpost

2018/9/20

#
Super_Hippo wrote...
Highscore is an Actor subclass, not a World subclass.
Then add a method in the world to get the Highscore object:
public Highscore getHighscore()
{
    return highscore;
}
and use the following:
((MyWorld)getWorld()).getHighscore().drawText();
Recorsi Recorsi

2018/9/20

#
Oh sry i forgot that. Sorry for the many questions but i have another one. How do i access the highscore which is saved on the server? The documentation says "getScore()". I think i have to implement it in this line...
img.drawString("Highscore: "+highscore, 10, 90);
... of my drawText method, but i cant just do "+ getScore()" or "+UserInfo.getScore()" right?
danpost danpost

2018/9/20

#
You must realize by now that all non-static methods must be executed on an object (or instance) of the class. The getScore method of the UserInfo class is executed on a UserInfo object. The getMyInfo method (a static method executed on the class itself) may return a UserInfo object that the method can be executed on. Again, you still need to check to make sure null is not returned before attempting to execute the method on what is returned.
You need to login to post a reply.
1
2