save and load game

Hello.
I want to implement saving and loading (from file) in my game that uses Kev’s Slick engine
I searched the forums, googled and found nothing useful…

So I am wondering what is the simplest way?
a) serialize all my objects for save and deserialize for load
b) manually save data in some file, like xml, and restore it manually by parsing
c) something else…

Any suggestions?

Serialize works for me.

Cas :slight_smile:

Serialization won’t work if you change the class files, so those save files will (usually) not work between different versions, not to mention that saves far more data than needed.
XML could work if you’ve got fairly little data to save. A custom binary format might work better if you’ve got lots of save data.

You can use a const mark to prevent that:

private static final long serialVersionUID = 123456789L; 

[quote]not to mention that saves far more data than needed.
[/quote]
You can sign what or what not to serialize (in light).

With Externalizable you can take all control of serialization… so you save what you want.

PD: this is my first post… so, hi to everybody. :slight_smile:

Don’t use Externalizable, it’s relatively slow and takes a long time to implement. Just make a custom serialVersionUID in each Serializable class. Many compilers will give you warnings if you don’t include one anyway.

But it’s pretty simple to just include an ObjectOutputStream and write it to a data file. Just be warned that constructors won’t be called upon the loading of an object. I usually create a single SavedObject that contains variables to learn how to construct loaded objects upon load. That way, changes I make in constructors are compatible across versions.

Well, that’s a bit of an oversimplification…

Great read