Old save files in updated game version

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
Yc3k
Newbie
Posts: 24
Joined: Tue Feb 27, 2018 8:27 pm
Contact:

Old save files in updated game version

#1 Post by Yc3k »

Hi all,

I'm having troubles with loading old save game files in New version of the game. I am using Ren'py web updater to update the game to a newer version but almost always old save game files don't work.

Now, I've read several posts on this topic and I have a few questions.

1. If I want to add a new variable in the game I need to use the "default" statement or I will get an error when loading an old save file? Trude or false?

2. If I add a new variable do I need to add them in a separate rpy file or can I just add them in my main script.rpy file?

3. If I want to add new dialogue or other content to a new version can I just add the content to an existing file (without changing the existing structure or labels) or do I need to add new content in a new rpy file?

4. If I change a certain dialogue in my game but don't change the order or line number or label name will this work and will it break my old save file after the update.

Thank you for your help.

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Old save files in updated game version

#2 Post by kivik »

Old save files generally break because you're checking a variable, or perform something that requires data which doesn't exist in the game save, or in the case of Renpy version changes - old renpy code being phased out.

The issue you've got is that Renpy wasn't designed for iterative updates in itself, it's down to you to manage that. You manage that by making sure that when your game is updated, that new changes are compatible. With that in mind, let's look at your questions:

1 - default statement won't solve your problem. The default statement just means when a player starts the game, the variable gets declared before the start label as part of the renpy code. The define on the other hand runs at game launch. This means loading a game wouldn't trigger the default statements at all.

That said, default statement should be used for any variables that will change during the game. e.g. stats, relationship points, branching variables etc. It's the easiest way to know that these variables will be saved. What you need to do with new variables instead, is to check when your game is loaded, whether the variables exist or not.

You can achieve this by using the after_load label, and within this block, execute codes that physically checks for the existence of all the new variables - and give them a default value if they don't exist.

FYI, this won't necessarily solve all issues. If you decided to add a variable that gets manipulated in existing code in the previous version (say you wanted to add a new choice in chapter one and now you're releasing chapter 2) - a player could save pass the code that manipulates the variable, and loading it would reset it to default value and not be representative of any choices.

The fact that you're doing iterative update to your game implies that you may not know all your variables to start with, so it's going to be potentially very difficult to account for all these things as your game grow.

There're a few things you can do to mitigate the problem:
- use default statement to declare a "game save version" variable, as well as a define statement to declare a "actual game version" variable. On the after_load label, compare the two and decide whether the save game is compatible or not, and stop the player from being able to proceed if the save is incompatible
- using the above, you could also call some other labels to declare missing variables if suitable
- in the case where a save file is beyond the new variable's manipulation, maybe use another default variable. I don't know how you're best to track this. renpy.seen_label seems to be persistent and not saved game only, so it may be quite hard to pull this one off

2 - No. You don't need to add new variables or new code in new files. That said, it's probably worth breaking your game down into multiple script files, some for initialisation, some for mechanics, some for story elements. It'll have no impact on your game at all where the code is.

3 - As before, just add it to your existing files and it'll work.

4 - This one I can't answer for certain, but I recommend you create a new game project and test it yourself. Create a label with 10 lines of dialogues, execute it and save it half way. Then add new dialogues before and after the code and see what happens when you load the game.

Yc3k
Newbie
Posts: 24
Joined: Tue Feb 27, 2018 8:27 pm
Contact:

Re: Old save files in updated game version

#3 Post by Yc3k »

Thank you so much for quick response. Your answers helped me understand better how renpy save file works.

Now, regarding my problem. My main variables are already set (stats, money, etc.) and I don't intend to change the anymore. What problem I have is following.

Let's say I write a certain dialogue for a char. At the end of that dialogue I want to trigger an one time variable so the game would know that I've done that conversation. Since I cannot predict this variable in advance my question is how do I create it so when the game updates it don't break the save file.

I was thinking on creating flag variables like flag_1, flag_2, flag_3, etc in hundreds so whenever I need to use a new variable I simply use the first available existing flag variable and put a comment besides it to know what it does. The problem with this system is it will be really difficult to track those flags later on when I'll have, a like 50 variables. And I'm talking about one time variables.

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Old save files in updated game version

#4 Post by kivik »

Assuming these flags are not going to be hit by players until they reach new dialogues that you create, you can just use a python dictionary and set key values as the game progresses. Then rather than checking the value of the variable, you check if the key exists in your dictionary. Something like this should work:

Code: Select all

default diag_dict = {}

label dialogue_1:
    "stuff here"
    $ diag_dict["dialogue1"] = True
    jump dialogue_2

label dialogue_2:
    "stuff here"
    $ diag_dict["dialogue2"] = True
    jump dialogue_3

label check_dialogues:
    if "dialogue1" in diag_dict:
        "Do something"
    return

rames44
Veteran
Posts: 233
Joined: Sun May 29, 2016 4:38 pm
Contact:

Re: Old save files in updated game version

#5 Post by rames44 »

@kivik - your statement about “default” is incorrect:

Text below taken from https://www.renpy.org/doc/html/python.html

The default statement sets a single variable to a value if that variable is not defined when the game starts, or after a new game is loaded.For example:

Code: Select all

default points = 0
When the variable points is not defined at game start, this statement is equivalent to:

Code: Select all

label start:
    $ points = 0
When the variable points is not defined at game load, it's equivalent to:

Code: Select all

label after_load:
    $ points = 0
So using “default” DOES help with new variables and old saves.

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Old save files in updated game version

#6 Post by kivik »

rames44 wrote: Wed Jul 18, 2018 6:45 pm @kivik - your statement about “default” is incorrect:

Text below taken from https://www.renpy.org/doc/html/python.html

The default statement sets a single variable to a value if that variable is not defined when the game starts, or after a new game is loaded.For example:

Code: Select all

default points = 0
When the variable points is not defined at game start, this statement is equivalent to:

Code: Select all

label start:
    $ points = 0
When the variable points is not defined at game load, it's equivalent to:

Code: Select all

label after_load:
    $ points = 0
So using “default” DOES help with new variables and old saves.

Ooh, thanks for clearing that up for me, I hadn't seen that so that's good to know. Sorry for the misinformation!

Yc3k
Newbie
Posts: 24
Joined: Tue Feb 27, 2018 8:27 pm
Contact:

Re: Old save files in updated game version

#7 Post by Yc3k »

So then using "default" statement when adding new variables should prevent the save game bug?

What about my old variables? Do I need to put them as default also? Especially those that changes all the time like energy and stats.

Thank you @kivik for your suggestion to use dicts. It's not a bad idea and I might consider using this instead of variables.

rames44
Veteran
Posts: 233
Joined: Sun May 29, 2016 4:38 pm
Contact:

Re: Old save files in updated game version

#8 Post by rames44 »

Yes. If you have a new variable in Version 2 of your game, and if you declare it using “default,” the variable will get the default value even if the user restores a save from Version 1. So no exceptions get thrown.

Declaring a value with “default” only sets the initial value at game start or load time. You’re free to update the value as often as you like during game play. As described on the page I referenced, the only effect of the “default” is to make sure the variable is defined no matter what, and that it’s among the variables that are saved. Other than that, it’s a normal variable

There would be no harm in going back and changing the variable declarations from Version 1 to use “default” in Version 2. Any value in a Version 1 save won’t be altered, since the default save/restore magic only applies to variables that don’t have a value in the save being restored.

“default” is DEFINITELY your friend when it comes to setting up variables!!
Last edited by rames44 on Thu Jul 19, 2018 1:09 pm, edited 1 time in total.

Yc3k
Newbie
Posts: 24
Joined: Tue Feb 27, 2018 8:27 pm
Contact:

Re: Old save files in updated game version

#9 Post by Yc3k »

Great, thank you very much for your help.

Only one question, you've sad that "define" is my friend while we were talking about "default" statement.

Not sure if it was a typo or you've mean I should use both?

rames44
Veteran
Posts: 233
Joined: Sun May 29, 2016 4:38 pm
Contact:

Re: Old save files in updated game version

#10 Post by rames44 »

Oops - typo. I've corrected the post. Sorry.

Yc3k
Newbie
Posts: 24
Joined: Tue Feb 27, 2018 8:27 pm
Contact:

Re: Old save files in updated game version

#11 Post by Yc3k »

Np, thank you very much for all the help.

Yc3k
Newbie
Posts: 24
Joined: Tue Feb 27, 2018 8:27 pm
Contact:

Re: Old save files in updated game version

#12 Post by Yc3k »

I have a couple more questions regarding this topic then I think I've got it figured out.

1. If I add a default variable for a new game version do I add them before or after the label "start"?
2. If I leave all the variables defined with a "default" statement or use "after_load" label will this mean that every time the game is loaded it will reset those variables to their default state or will it use the "saved" state from the save file?

Sorry if this is a stupid question, but I'm still learning the ropes of Ren'py and Python.

User avatar
xavimat
Eileen-Class Veteran
Posts: 1460
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love, unknown
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Contact:

Re: Old save files in updated game version

#13 Post by xavimat »

Not a stupid question, it's a very important thing to understand with renpy.

1. The "default" statement is not part of a label. It is executed at init time (before the main menu appears). So you don't put them after the label start but outside any label. That means that you can put them in any .rpy file, as you wish, to organize your files.
2. If you put a "default" statement inside the after_load label, you are putting it wrong (default statements go outside any label, they execute at init time).
If you simply assign a value to a variable in label after_load, it will be always assigned to the variable every load, so it's not really useful. You'd need to check that variable with if/else, but that's more complex.
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

Yc3k
Newbie
Posts: 24
Joined: Tue Feb 27, 2018 8:27 pm
Contact:

Re: Old save files in updated game version

#14 Post by Yc3k »

***EDIT***

OK, I think I finally understand how the default statement works and how can I use it when updating the game to a newer version. Thank you very much. I'll go test it now.

Post Reply

Who is online

Users browsing this forum: Google [Bot]