Page 1 of 1

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

Posted: Sun Nov 05, 2023 5:12 am
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

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

Posted: Sun Nov 05, 2023 3:14 pm
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:
        ....

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

Posted: Fri Nov 10, 2023 9:07 am
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