—
EDIT: I just realized that the “right” answer to this is maybe a little bit to advance for me at the moment. I want to focus on adding stuff to the game at this moment and not making the best save/load system. I’ve taken your suggestions and you’ve opened my mind for loads of great stuff to do in the future. Mainly labeling the data saved (maybe using XML).
For the moment i’ll just add some primitive function to make it work at this stage of development.
—
I need some help breaking out a logical and nice way of doing this. It’s for a game i’m making using c++ and SDL. I need some help with the save/load stuff. Basically when i save a game there are some stuff that will always be there (player name, position, gold ect..). But there are also some dynamically saved content, like stats, equipped items and items in the inventory (in the future finished quests will be saved here as well).
I have no problem saving this data down, it’s easy. The problem i have is how to structure it’s breakpoints when reading the data. This is an example of how a savefile might look:
CharName (some variables like positions that will always be saved)
(the first statMap looks like this “string int” fetched from
map) (second statMap, it’s the same) (equipped items, one
item is split into three parts “string name int ID string
description”) (items in inventory, the same as the last one)
I hope you understand my example. I’d like some help understanding a logical way to structure this. I’m thinking of maybe ending each dynamic sequence with a char and then load the line up to that char in a string. Then i split that string into several parts. But that sound like an awful amount of steps. Could you help me out?
A very common method for structuring datafiles in games is to use a header and a body: in the header you define the structure of the content in the body based around offsets:
e.g Data for character stats begins at offset 10054, and continues for 2120 characters (you must define and use a standard character size to make this work).
Then when you read it you read the header to get the structure, and then load the data from the areas that it specifies.