New versions, save compatibility, and set new variables to 0

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
Zeroized
Regular
Posts: 33
Joined: Sat Mar 23, 2013 12:33 am
Contact:

New versions, save compatibility, and set new variables to 0

#1 Post by Zeroized »

Greetings, and thanks for your earlier help.
I've fixed most of my issues with Ren'py and Python, tumbling around, doing stuff. I've made some demos and I've ended pretty satisfied with the final result.
I've decided to build an episodic game, and release new content every month or so. But then I realized that every new build will have new variables, rendering the old saves useless. Since the inability to use saves in between versions could be a dealbreaker, I'm wondering if there is any way to check if there are new variables running when you load a game, and if those variables aren't defined, set them to 0 to avoid "variable non-defined" errors.

User avatar
PyTom
Ren'Py Creator
Posts: 16093
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: New versions, save compatibility, and set new variables

#2 Post by PyTom »

Yes, you do:

Code: Select all

label after_load:
     $ store.newvar = getattr(store, "newvar", 0)
     return
There are other ways to test for presence/absence, so take this as mostly a guideline.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

User avatar
Zeroized
Regular
Posts: 33
Joined: Sat Mar 23, 2013 12:33 am
Contact:

Re: New versions, save compatibility, and set new variables

#3 Post by Zeroized »

Thanks for the answer.
Where do I add this, though? And I assume "newvar" is the name of the new variable. Do I need to check for every new variable added?

Post Reply

Who is online

Users browsing this forum: Google [Bot]