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
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();
}
}


