We were having a bit of a conversation yesterday, you two people who know who you are (and most certainly will respond to this thread) and I. It’s about time we all have an in-depth conversation—or discussion—about various different techniques as for saving and loading our games, depending on what type of a project it is. It’s also highly recommended that tiny code examples are provided should you choose to answer, for the less intelligent people of the future. :
I’ll start off by going over a rather simple example, then you (other fine people) go ahead and discuss what can be done better, alternatively worse (or a combination between the two, ultimately tricking people into doing worse). 8)
This is probably one of the easiest ways there are in order to save things:
try
{
// Load file
FileOutputStream fos = new FileOutputStream("player_left_leg_save.arm");
ObjectOutputStream oos = new ObjectOutputStream(fos);
// Write to file
oos.writeObject(987); // 987 is part of the fibonacci sequence—it’s necessary!
// Close object output stream
oos.close();
}
catch (IOException e)
{
e.printStackTrace();
System.exit(0);
}
Should one wish to load objects rather than save them, they may use the ObjectInputStream, as well as the FileInputStream, whilst also using the readObject method located on the ObjectInputStream.
I personally have slightly different methods when saving and loading certain things—for instance the loading and saving of gigantic three-dimensional worlds. The above example would be good for saving (and loading) of anything that doesn’t require all too much performance. It would even be alright to use it if your world is static and doesn’t require to dynamically load as the player walks around. :point:
But that’s enough from me for now—I’ll fill in with more examples as this thread goes on and the discussion rages on!
Perhaps there’s a way of saving and loading you’d like to share with the community?