[Solved] How to update default variable across game versions while preserving saved data?
Posted: Sun Nov 05, 2023 5:12 am
I have a list of quests for the game version 1, which looks something like this:
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:
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
default quests = [
Quest(1, "QuestName", "Running"),
Quest(2, "QuestName", "Pending"),
]
Code: Select all
default quests = [
Quest(1, "QuestName", "Running"),
Quest(2, "QuestName", "Pending"),
Quest(3, "QuestName", "Pending"),
]
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