Page 1 of 1

Implementing a save feature

Posted: Mon Aug 03, 2009 5:36 pm
by hayk0510
How would you go about implementing a save feature in a game? I was thinking about this the other day and can't find anything about it on Google.

I was thinking something like writing keywords to a file depending on the state of the game, then the game would check the words and restore the previous game state.

Is it something like that, or will I have to get involved with a database? Also, are there any specific game programming books or tutorials you guys know of? Not in any specific language, or how to draw and move stuff on the screen. But something that shows you how to implement game saves, split screen configurations, and various other algorithms specific to game programming?

Re: Implementing a save feature

Posted: Mon Aug 03, 2009 5:40 pm
by dandymcgee
I've never actually done this before, but I believe "serialization" would be the keyword you're looking for.
I'm sure someone more experienced can give you a bit more information about how to go about implementing such a thing.

Re: Implementing a save feature

Posted: Mon Aug 03, 2009 5:50 pm
by hayk0510
dandymcgee wrote:I've never actually done this before, but I believe "serialization" would be the keyword you're looking for.
I'm sure someone more experienced can give you a bit more information about how to go about implementing such a thing.
Awesome! Thanks, time to visit my good friend Google :D

Re: Implementing a save feature

Posted: Mon Aug 03, 2009 6:32 pm
by andrew
You might have missed this:
Writing your own Load / Save routines

It's all C, but it should give you a few ideas.

Re: Implementing a save feature

Posted: Tue Aug 04, 2009 7:23 am
by Falco Girgis
This totally, 100% depends on your engine. It could be as simple as writing and reading a few lines of text to literally dumping class states in binary and slurping them back up.

Re: Implementing a save feature

Posted: Tue Aug 04, 2009 9:23 am
by trufun202
Yeah, I'm a fan of serialization myself. You are essentially taking something in memory (your GameState object) and dropping it to disk (binary, xml, etc.). Then, when the game is loaded, you take that file on disk and reinstantiate the object in memory. However, as Falco mentioned, it depends on your engine. Using serialization requires that your game's current state data is wrapped up into a class (or set of classes), which can be quite an overhaul in some cases.

Re: Implementing a save feature

Posted: Tue Aug 04, 2009 9:28 am
by Pickzell
Never tried it in C/++, but in MMF2 I just stored all the data in an array, which was then sent to an .ini or a .txt and then just read that through.

My friend wrote his own super secret code language to do this, here is a save file from his game(.ini)

Code: Select all

[Kh{h]
{imvylz{wvpu{z=7
{imvylz{ivzzwvpu{z=7
{hmvylz{wvpu{z=7
{hmh{i|{{zwvpu{z=7
{hmh{i|{{zivzzwvpu{z=7
[Sl}lszJvtwsl{l]
{imvylz{=7
{hmvylz{=7
{hmh{i|{{z=7
[Vw{pvuz]
mvylz{kl{hps=:
lmmlj{zkl{hps=8
[Jolh{z]
is|ukly=7
is|uklyvu=7
tph=7
tphvu=7
pumpup{l|s{yh=7
pumpup{l|s{yhvu=7
pumpup{lolhs{o=7
pumpup{lolhs{ovu=7

Re: Implementing a save feature

Posted: Tue Aug 04, 2009 12:03 pm
by dandymcgee
Pickzell wrote:Never tried it in C/++, but in MMF2 I just stored all the data in an array, which was then sent to an .ini or a .txt and then just read that through.

My friend wrote his own super secret code language to do this, here is a save file from his game(.ini)

Code: Select all

[Kh{h]
{imvylz{wvpu{z=7
{imvylz{ivzzwvpu{z=7
{hmvylz{wvpu{z=7
{hmh{i|{{zwvpu{z=7
{hmh{i|{{zivzzwvpu{z=7
[Sl}lszJvtwsl{l]
{imvylz{=7
{hmvylz{=7
{hmh{i|{{z=7
[Vw{pvuz]
mvylz{kl{hps=:
lmmlj{zkl{hps=8
[Jolh{z]
is|ukly=7
is|uklyvu=7
tph=7
tphvu=7
pumpup{l|s{yh=7
pumpup{l|s{yhvu=7
pumpup{lolhs{o=7
pumpup{lolhs{ovu=7
Yeah, plaintext is never a good idea if you plan on having any sort of respectable scoring system.
Even if you make it only slightly harder to edit the save file, it's much more likely people will play your game legitimately the first time through.

Re: Implementing a save feature

Posted: Tue Aug 04, 2009 1:10 pm
by programmerinprogress
I guess you could do a bitwise not on all of the characters in the file to get around that problem, or at least the score part of the file, or some wacky and confusing language only your program understands, it's all good really :lol: