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

2012/10/18

Saving game state in greenfoot?

jahama jahama

2012/10/18

#
I am making games in greenfoot, and wanted to make a ingame shop spending points earned from playing, but I cant find out if it is possible to save the game state? Please help!
danpost danpost

2012/10/18

#
The easiest way to 'hold' the game while processing shop action is to create a new world for the shop. You will need to call the new world with a reference to the old world so you can return to it. Check out my Crayon Babies scenario which demonstrates changing worlds.
jahama jahama

2012/10/18

#
Yes, I know how to change worlds, but when either reloading the page, or starting the game again, and then all is gone. I want to save what items you have bought, and to save which levels you have done, so you dont need to start over again.
SimpleJack SimpleJack

2012/10/18

#
you could just save all your variables/data to a file and then re read them with some encryption to avoid them haxors
danpost danpost

2012/10/18

#
Everything will be saved in the variable that holds the original world while the shop is up. In the original world class when going to the shop world
Greenfoot.setWorld(new ShopWorld(this));
In the ShopWorld world
// instance variable
private World mainWorld;
// constructor
public ShopWorld(World world)
{
    super(600, 400, 1); // whatever
    mainWorld = world;
    // other code
}
// when conditions are right to return
Greenfoot.setWorld(mainWorld);
Everything will be just as it was when you called ShopWorld.
davmac davmac

2012/10/19

#
jahama, the UserInfo class can be used to store player-specific data which persists between sessions (page refresh etc). Take a look at the documentation for it.
You need to login to post a reply.