thx for helping but the problem stay, I make the code like you say danpost but there stil is a red square on pirvate "PlayerData" playerl; ("...." is red square) I hope now you no what the problem is
import greenfoot.*;
public class Saver
{
private PlayerData player;
public Saver()
{
if (PlayerData.isStorageAvailable() ) {
if (PlayerData.getMyData() != null) {
player = PlayerData.getMyData();
}
}
}
public void saveHighscore(int score)
{
if (PlayerData.isStorageAvailable() ) {
if (PlayerData !=null) {
if (score > PlayerData.getScore() ) {
PlayerData.setScore(score);
PlayerData.sore();
}
}
}
}
}
Why do you do:
PlayerData.setScore(score);
PlayerData.store();
Do:
player.setScore(score);
player.store();
You can't store or set the score for the class PlayerSata, you have to do that with your instance variable.
Have you tried using the menu item Edit | Import Classes... and select ScoreBoard. It looks like it has the complete code necessary for posting a score board but if you want to write your own.... I guess its good experience
-- Takashi
davmac sorry for my lost respont but I have version 2.1.2 and maby thats the problem but where can I download the new version of greenfoot than I hope you can help me.
Sorry for my stupid action and the first code works great but I don´t understand the last code. I make a hiscore but I don´t know what I need than plz giff me some advice
than I mean from this text I don´t understand because if I put the code in there stay unspected user plz help
Now we need to create a saver. Go to Ground and scroll down to the gameOver() method, and add these lines at the bottom of it:
Saver saver = new Saver();
saver.saveHighscore(counter.getValue());
These lines simply create a save and let that saver save the current score of the counter.
All we need to do now is create a score board, so you can see your score and other’s scores.
Import the class ScoreBoard, by going to edit--->import class--->ScoreBoard.
Change gameOver() in Ground to:
removeObject(user);
Saver saver = new Saver();
saver.saveHighscore(counter.getValue());
ScoreBoard board = new ScoreBoard(600, 350);
addObject(board, getWidth() /2, getHeight() /2);
This creates a scoreboard and puts it into the world.