Hey everybody.
So I am working on a game similar to asteroids and I am showing a personal HighScore in the top right corner.
Whenever I try to run the game outside of an account it crashes ( its because I call myInfo.getScore() I believe)
The code works perfectly fine when a user is logged into an account.
My question is how do I fix it so it does not crash when there is no account logged in?
I am perfectly fine with it not keeping score of a non logged in user
Thank you for your time
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) public class HighScore extends Actor { UserInfo myInfo = UserInfo.getMyInfo(); int highScore = 0 ; int newScore = 0 ; public void HighScore() { if (UserInfo.isStorageAvailable()) { highScore = myInfo.getScore(); } draw(); } public void setHighScore( int newScore) { if (UserInfo.isStorageAvailable()) { if (newScore > myInfo.getScore()) { myInfo.setScore(newScore); myInfo.store(); // write back to server highScore = newScore; } else { highScore = myInfo.getScore(); } } draw(); } public void draw() { setImage( new GreenfootImage( "HighScore : " +highScore, 24 ,Color.WHITE,Color.BLACK)); } public void act() { draw(); } } |