Implementing a save feature

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
hayk0510
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 21
Joined: Tue Mar 10, 2009 11:03 pm

Implementing a save feature

Post 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?
"Manually managing blocks of memory in C is like juggling bars of soap in a prison shower: It's all fun and games until you forget about one of them."
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Implementing a save feature

Post 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.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
hayk0510
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 21
Joined: Tue Mar 10, 2009 11:03 pm

Re: Implementing a save feature

Post 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
"Manually managing blocks of memory in C is like juggling bars of soap in a prison shower: It's all fun and games until you forget about one of them."
andrew
Chaos Rift Regular
Chaos Rift Regular
Posts: 121
Joined: Mon Dec 08, 2008 2:12 pm

Re: Implementing a save feature

Post 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.
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: Implementing a save feature

Post 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.
User avatar
trufun202
Game Developer
Game Developer
Posts: 1105
Joined: Sun Sep 21, 2008 12:27 am
Location: Dallas, TX
Contact:

Re: Implementing a save feature

Post 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.
-Chris

YouTube | Twitter | Rad Raygun

“REAL ARTISTS SHIP” - Steve Jobs
User avatar
Pickzell
Chaos Rift Junior
Chaos Rift Junior
Posts: 233
Joined: Sat May 16, 2009 10:21 am

Re: Implementing a save feature

Post 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
I'm an altogether bad-natured Cupid.
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Implementing a save feature

Post 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.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
programmerinprogress
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Wed Oct 29, 2008 7:31 am
Current Project: some crazy stuff, i'll tell soon :-)
Favorite Gaming Platforms: PC
Programming Language of Choice: C++!
Location: The UK
Contact:

Re: Implementing a save feature

Post 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:
---------------------------------------------------------------------------------------
I think I can program pretty well, it's my compiler that needs convincing!
---------------------------------------------------------------------------------------
And now a joke to lighten to mood :D

I wander what programming language anakin skywalker used to program C3-PO's AI back on tatooine? my guess is Jawa :P
Post Reply