[Solved] How to update default variable across game versions while preserving saved 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
Wildly
Newbie
Posts: 7
Joined: Mon Sep 25, 2023 2:05 pm
Contact:

[Solved] How to update default variable across game versions while preserving saved data?

#1 Post by Wildly »

I have a list of quests for the game version 1, which looks something like this:

Code: Select all

default quests = [
    Quest(1, "QuestName", "Running"),
    Quest(2, "QuestName", "Pending"),
]
But in the future, let's say in the game version 2 I want to add another quest to the list, so the full list would look like this:

Code: Select all

default quests = [
    Quest(1, "QuestName", "Running"),
    Quest(2, "QuestName", "Pending"),
    Quest(3, "QuestName", "Pending"),
]
The problem is that the game save only stores the initial version of the variable. If I were to add or remove quests later, the variable remains in the same state as it was in the first version.
So, my question is how to update this default variable when I add a new quest to the list in a future version of the game.

Players might play an older version of the game, save it, and then continue playing the newer version, but the saved data would still contain the old quest list.


I have some pseudo code, but I don't know how to implement it properly in this situation:

Code: Select all

# Check if the new quest is already in the list of default quests.
  if new_quest not in default_quests:
    # If the new quest is not in the list of default quests, add it to the end of the list.
    default_quests.append(new_quest)

  # Return the updated list of default quests.
  return default_quests
Last edited by Wildly on Fri Nov 10, 2023 9:09 am, edited 1 time in total.

User avatar
m_from_space
Eileen-Class Veteran
Posts: 1011
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: How to update default variable across game versions while preserving saved data?

#2 Post by m_from_space »

Just check for the quest data inside the special label "after_load", which is executed right after a player loads a game.

Code: Select all

label after_load:
    if "some_quest" not in quests:
        ....

Wildly
Newbie
Posts: 7
Joined: Mon Sep 25, 2023 2:05 pm
Contact:

Re: How to update default variable across game versions while preserving saved data?

#3 Post by Wildly »

m_from_space wrote: Sun Nov 05, 2023 3:14 pm Just check for the quest data inside the special label "after_load", which is executed right after a player loads a game.

Code: Select all

label after_load:
    if "some_quest" not in quests:
        ....
Thank you very much! That's what I need

Post Reply

Who is online

Users browsing this forum: Bing [Bot]