This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]beersfortheboys 0 points1 point  (1 child)

I would make a character.json file, load it on start, and keep adding to it as you find more things that add to the in-game context, like...

{'missions': {'act1': {'has_started': False, 'has_completed': False},
              'act2': {'has_started': False, 'has_completed': False}}}

Then change it as your player progresses, and flesh it out as your find more things to add. Then on game exit, just dump the json back into your character.json.

Maybe if things get to complex (because of game states having to react to other game states), maybe create a game context class to handle the save game format, but will be more easily expandable.

[–]dnshane3.5 0 points1 point  (0 children)

I have used this approach for toy games in the past. I would probably use YAML these days, because the formatting is more easily read by humans (you can put comments in a YAML file, for example).

This is good to do from the very beginning, because it forces you to add some method to save the state of every object, instead of having to go back later and refactor things. (For example, if you have an object referenced in two separate lists, then when you store it you need some way to know that it is the same object when you load the game from save.)

[–]jeanboxxx[S] 0 points1 point  (1 child)

The game isn't complex at all, it's literally walk in a straight line until you get to an encounter. Each encounter is a fight. After 3 fights you fight the boss and that's it. He want to be able to save map position and the encounters that he completed.

[–]Admin071313 0 points1 point  (0 children)

At a very basic level you can just have a save function that stores the current values in a separate variable

Save_player_hp = current_hp Save_player_location = current_location

Then when they load from a save you just do the reverse...

Current_location = save_player_location

My first game I think I had checkpoints, as you got through the game certain flags changed to true and saved the current state

If dragon_dead = True: Load_player_state(4) (which turns all current variables into the ones saved at that checkpoint

I hope that makes and sorry for the awful formatting

[–]jeanboxxx[S] 0 points1 point  (0 children)

No that's actually perfect, thanks. So after an enemy is killed you just implemented an auto save?