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

2014/4/30

Storing, retrieving and printing high scores

karolis karolis

2014/4/30

#
This is the code im using to retrieve and print, but nothing is appearing. I have used both "UserInfo.getMyInfo().getScore();" and "Score" with same results. I dont think its a problem with the "drawImg" procedure as i have used it before and it has worked fine.
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
import java.awt.Font;

public class getHighScores extends Actor
{
    private int score;
    public getHighScores()
    {
        setImage(new GreenfootImage(150, 60));
        getScore();
    }
    
    public int getScore()
    {
        return UserInfo.getMyInfo().getScore();
        //return Score;
    }
    
    public void drawImg()
    {
        score = getScore();
        
        GreenfootImage image = new GreenfootImage(150, 60);
        image.setColor(Color.WHITE); //my background is black
        float fontSize = 35.0f;
        Font font = image.getFont().deriveFont(fontSize);
        image.setFont(font);
        
        image.drawString("" + score, 50, image.getHeight()/2);
        setImage(image);
    }
}
How could i go about saving and retrieving the top 10 scores from multiple players? this is the code i am currently using to save:
if (UserInfo.isStorageAvailable())
{
    UserInfo myInfo = UserInfo.getMyInfo();
    if (ScoreBoard.Score > myInfo.getScore())
    {
        myInfo.setScore(ScoreBoard.Score);
        myInfo.store();
    }
}
Also, is there a way to bring the Player change pop up box, without manually pressing CMD + SHIFT + P ? Thank you
karolis karolis

2014/4/30

#
.
danpost danpost

2014/4/30

#
Replace lines 10 and 11 in the getHighScores class with 'drawImg();'. Not that this will fix everything. Instead of CMD+SHIFT+P, you can use the menubar with "Edit>Preferences", or press CTRL-COMMA; then, choose the Miscellaneous tab, and change it there.
karolis karolis

2014/4/30

#
Thanks, what I meant was whether I could bring it up via commands, so when a procedure was called when the project is running
danpost danpost

2014/4/30

#
There is no way to change the current user while the project is running.
You need to login to post a reply.