Saving and loading game data

Anything related in any way to game development as a whole is welcome here. Tell us about your game, grace us with your project, show us your new YouTube video, etc.

Moderator: PC Supremacists

User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: Saving and loading game data

Post by Ginto8 »

N64vSNES wrote:
dnxviral wrote:Not what we save but how we save it.
Obviously the only way to get data static from a program executing and terminating would be to save it to a file.
Kinda funny how you completely and utterly failed to answer the question he asked. What he's talking about is Serialization, how you take an in-game data structure and put it in a file. The answer is that you have a lot of different choices, mainly depending on what the data itself is. Just look up some info on serialization, google is your friend ;)
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
User avatar
thejahooli
Chaos Rift Junior
Chaos Rift Junior
Posts: 265
Joined: Fri Feb 20, 2009 7:45 pm
Location: London, England

Re: Saving and loading game data

Post by thejahooli »

ginto8 wrote:Kinda funny how you completely and utterly failed to answer the question he asked. What he's talking about is Serialization, how you take an in-game data structure and put it in a file. The answer is that you have a lot of different choices, mainly depending on what the data itself is. Just look up some info on serialization, google is your friend ;)
Most of the time you wouldn't want this in games though. Object serialisation is not normally necessary. If this is what he meant and he has a good reason for saving an entire object, then it would be useful and a good way of doing it. However in most situations whole objects are not needed to be saved, only parts of it, and saving the whole object would potentially increase file size and loading times.
I'll make your software hardware.
N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

Re: Saving and loading game data

Post by N64vSNES »

Ginto8 wrote:
N64vSNES wrote:
dnxviral wrote:Not what we save but how we save it.
Obviously the only way to get data static from a program executing and terminating would be to save it to a file.
Kinda funny how you completely and utterly failed to answer the question he asked. What he's talking about is Serialization, how you take an in-game data structure and put it in a file. The answer is that you have a lot of different choices, mainly depending on what the data itself is. Just look up some info on serialization, google is your friend ;)
Oh my bad XD

Supposing you had a inventory containing 3 potions and 2 cookies ( why? I dunno cookies rock ).
Your inventory actully probably looks like this:

Code: Select all

1 1 1 2 2
or

Code: Select all

1 1 1 2 2 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
Or somthing of the sort anyways. So you could ouput this to a file and then when it gets reloaded set your inventory to what it read in.

Your save file could look like this:

Code: Select all

Noob -- Name
22     -- Up to level 22
75     -- You had 25 HP before you quit the game
2054 1023 666 -- X, Y and Z coords you were at when you saved
1 1 1 2 2 0 0 -- Your items
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
From this you could do somthing like this in the program

Code: Select all

shit = LoadShit()
for i = 0 20 do this
if shit.Items(i) not = 0 then
Player.GiveItem(shit.Items(i));
end
end
Player.SetName(shit.Name)
Player.SetHealth(shit.health)
Player.SetCoords(shit.x,shit.y,shit.z)
Level.LoadLevel("Level" + shit.levelnum + ".level")
Crappy example ( no perticular launguage )

But this could do well for somthing like a linear level 1, level 2, level 3 type game. ( Or at least thats how I would go about it )
dnxviral
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 51
Joined: Tue Dec 14, 2010 6:49 pm
Favorite Gaming Platforms: PC
Programming Language of Choice: Everything... and C#
Location: dnXstudios
Contact:

Re: Saving and loading game data

Post by dnxviral »

Haha Yea I know what your trying to get at. Cookies ftw.
Ginto8 wrote:
N64vSNES wrote:
dnxviral wrote:Not what we save but how we save it.
Obviously the only way to get data static from a program executing and terminating would be to save it to a file.
Kinda funny how you completely and utterly failed to answer the question he asked. What he's talking about is Serialization, how you take an in-game data structure and put it in a file. The answer is that you have a lot of different choices, mainly depending on what the data itself is. Just look up some info on serialization, google is your friend ;)
Yes and No. I'm trying to secure data to make it virtually impossible for somebody to change their stats, game position, items, etc.
I have map xml files and later items that would be defined through xml files, but these will be stored remotely and the player has no influence over them.
I'm not sure how to save my player's profile securely so it can't be, in a way influenced.
User avatar
thejahooli
Chaos Rift Junior
Chaos Rift Junior
Posts: 265
Joined: Fri Feb 20, 2009 7:45 pm
Location: London, England

Re: Saving and loading game data

Post by thejahooli »

You could encode the data in the file, I've never really had experiance with this but I'm sure something will come up if you google it.
To be fair you are never going to have a completely secure save data, because after all it is only data, which can be modified in some way regardless of your best efforts.
I'll make your software hardware.
N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

Re: Saving and loading game data

Post by N64vSNES »

The is no such thing as "secure" data since anything can be decoded.

The simplest way I'd suggest would be to encode the file like thejahooli said, the advantages to this being unreadable is that the file size will be very small and loading shouldn't take too much time.
dnxviral
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 51
Joined: Tue Dec 14, 2010 6:49 pm
Favorite Gaming Platforms: PC
Programming Language of Choice: Everything... and C#
Location: dnXstudios
Contact:

Re: Saving and loading game data

Post by dnxviral »

thejahooli wrote:You could encode the data in the file, I've never really had experiance with this but I'm sure something will come up if you google it.
To be fair you are never going to have a completely secure save data, because after all it is only data, which can be modified in some way regardless of your best efforts.
Encoding sounds.... fun. And I wouldn't mind if somebody edited the file and have their game file be corrupt either
N64vSNES wrote:The is no such thing as "secure" data since anything can be decoded.

The simplest way I'd suggest would be to encode the file like thejahooli said, the advantages to this being unreadable is that the file size will be very small and loading shouldn't take too much time.
Would be smaller?
How would you do the encoding?/What would you use for the encoding?
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: Saving and loading game data

Post by dandymcgee »

The only secure way is to store data on a server where they can't directly edit a file.
For your purposes saving the file as binary ought to deter cheaters without completely disallowing hardcore modders having fun. 8-)
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

Re: Saving and loading game data

Post by N64vSNES »

dnxviral wrote:
thejahooli wrote:You could encode the data in the file, I've never really had experiance with this but I'm sure something will come up if you google it.
To be fair you are never going to have a completely secure save data, because after all it is only data, which can be modified in some way regardless of your best efforts.
Encoding sounds.... fun. And I wouldn't mind if somebody edited the file and have their game file be corrupt either
N64vSNES wrote:The is no such thing as "secure" data since anything can be decoded.

The simplest way I'd suggest would be to encode the file like thejahooli said, the advantages to this being unreadable is that the file size will be very small and loading shouldn't take too much time.
Would be smaller?
How would you do the encoding?/What would you use for the encoding?
Yes the file size will be much smaller.
Depends on what launguage you are using for encoding the file.

Its basically just working with bytes rather than numbers.

1 byte = 1 byte
1 integer = 4 bytes
dnxviral
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 51
Joined: Tue Dec 14, 2010 6:49 pm
Favorite Gaming Platforms: PC
Programming Language of Choice: Everything... and C#
Location: dnXstudios
Contact:

Re: Saving and loading game data

Post by dnxviral »

dandymcgee wrote:The only secure way is to store data on a server where they can't directly edit a file.
For your purposes saving the file as binary ought to deter cheaters without completely disallowing hardcore modders having fun. 8-)
Haha nice

N64vSNES wrote:
dnxviral wrote:
thejahooli wrote:You could encode the data in the file, I've never really had experiance with this but I'm sure something will come up if you google it.
To be fair you are never going to have a completely secure save data, because after all it is only data, which can be modified in some way regardless of your best efforts.
Encoding sounds.... fun. And I wouldn't mind if somebody edited the file and have their game file be corrupt either
N64vSNES wrote:The is no such thing as "secure" data since anything can be decoded.

The simplest way I'd suggest would be to encode the file like thejahooli said, the advantages to this being unreadable is that the file size will be very small and loading shouldn't take too much time.
Would be smaller?
How would you do the encoding?/What would you use for the encoding?
Yes the file size will be much smaller.
Depends on what launguage you are using for encoding the file.

Its basically just working with bytes rather than numbers.

1 byte = 1 byte
1 integer = 4 bytes
ahh ok. I'll look into both approaches. Server side, and files. Thanks!
Post Reply