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

2012/8/30

How to save something when the program isn't running?

Mux Mux

2012/8/30

#
I'm about to bring up a program with a nearby free to play world. So there are a big amount of variables and i want to save them even if i shutdown my computer and restart the game. I know it is possible to write a text and save it in an complex way. May be I'm wrong? I would like to know how to do this. I tried to figure it out by myself but i can't get it right.
SPower SPower

2012/8/30

#
What do you mean with 'when program isn't running'? Do you mean when the pause button was pressed or something else?
Mux Mux

2012/8/30

#
something else : What i mean is i playing the game. Press the save Button. ( or something this way) End up everything. And be able to start the program and click on something like "loading game" and go on where i stopped playing. EDIT: Maybe something like save and click the restart / compile Button
SPower SPower

2012/8/30

#
First you need to create the save button. If you don't know how, look at a tutorial I created: http://www.greenfoot.org/scenarios/5679 Implement the buttonPressed method like this:
public void buttonPressed(Button button)
{
      if (/* the button is the save button */) {
            saveGame(); // or something like that
            // if you just wanna stop the program
            Greenfoot.stop();
            // if you wanna close the window:
            System.exit(0);
      }
}
Mux Mux

2012/8/30

#
Yeah i got a class called "Button" with all my Buttons in it thats not the mean problem but thx for explaining it. The mean problem is to save something in any type to get the data stored. I can't do something with level, because i got this open world and your able to build something in it. Create a password which displays all locations, types and etc. from the things in the world and type it in manual is impossible. So there is the problem: How to create a save file of any kind?
SPower SPower

2012/8/30

#
I would just suggest creating a .txt file, instead of something more complex. This scenario is very helpful: http://www.greenfoot.org/scenarios/4548
Mux Mux

2012/8/30

#
Nice thats what I'm searching for. Really really great.
You need to login to post a reply.