I am making a D&D text-based game and wanted to make a save progress function where python would save a particular function that I made (such as episode 01) and would load the progress when user calls it. I am trying to use jsonpickle to do so, but am unable to load the file since it is not printing anything even though there is data in the file and is encoded in jsonpickle. Here is the code:
def load_game():
"""Load game state from a predefined savegame location
and return the game state contained in that savegame.
"""
with open("savegame.json", 'r') as savegame:
state = jsonpickle.decode(savegame.read())
return state
def save_game():
global game_state
with open(SAVEGAME_FILENAME, 'w') as savegame:
savegame.write(jsonpickle.encode(game_state))
This is what is stored in my file:
{"py/function": "__main__.scene1"}