Proper method of editing save-game data

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
theCodeCat
Regular
Posts: 62
Joined: Sun Sep 06, 2015 8:40 pm
Projects: Lucid9, Mystic Destinies: Serendipity of Aeons
Skype: theCodeCat
Contact:

Proper method of editing save-game data

#1 Post by theCodeCat »

Hi,

For a project I'm working with I want to make sure that save files from old versions can be loaded by new versions.
Since the format in which data is stored may change, I'd like to setup a function that can modify save data after it has been loaded.

To give a basic example, let's say in version 1 an integer value is stored directly in "store.someVar" however in version 2 it gets stored in a wrapper class.
So upon loading a save I'd like something like this to run:

Code: Select all

if store.version == 1:
    store.someVar = Wrapper(store.someVar)
However as I understand it, a save-file doesn't just save the current state, it also saves a history of previous states in case the user wishes to rollback.
And from what I understand from looking at the source, these "states" are chained together and just store how data got changed between them.
So if upon loading a file I want my update code to run on *all* saved states, how would I do that?

(Running the update code everytime a rollback occurs is also an option, but I'd prefer it if it only happens when a file is loaded)

Thanks

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2402
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Proper method of editing save-game data

#2 Post by Ocelot »

Did you consider simply blocking rollback past current point in case player loads save file with version mismatch?
< < insert Rick Cook quote here > >

User avatar
theCodeCat
Regular
Posts: 62
Joined: Sun Sep 06, 2015 8:40 pm
Projects: Lucid9, Mystic Destinies: Serendipity of Aeons
Skype: theCodeCat
Contact:

Re: Proper method of editing save-game data

#3 Post by theCodeCat »

Ocelot wrote: Tue Dec 07, 2021 4:09 pm Did you consider simply blocking rollback past current point in case player loads save file with version mismatch?
I did. It's an option but it feels like a work-around when I want to know how to do it "properly".

That said, maybe that's the better approach anyway. Rollback history might not be reliable if there have been major version changes

Post Reply

Who is online

Users browsing this forum: munni