Best way to go about programming a Dark Souls like save game system?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Ciavarie

After making a quest and dialogue system, I find myself in a position where I need a save game system. The best suited one for my game would be one that autosaves and can’t be controlled by the one in front of the screen (reverting decisions should not be possible).
I need to save basic things like player health, mana, equipment, inventory state, chests, etc. and… the players position.
My (maybe naive) strategy would be to create a file which saves these things as dictionaries and update it whenever the player changes equipment, opens a chest, etc.
But this requires to always open the file, write to it and close it again for EVERY move, for every injury in battle, etc. And I intend to save the enemies position and health status as well, so it is not possible to quit out and every foe is at its spawn location (like it is possible in dark souls).
For the movement I could maybe use a timer of 5 to 10 seconds to reduce the rate of saves, but I would still like to know if there is a better (and maybe less resource consuming) way to go about this.
And of course to update the file content I always need to go through the entries until I find whatsoever needs to be updated. So maybe it would be better to have multiple files (one for the player, one for chests, etc.) and load them one by one on startup?

Does anyone have some clues on the matter? Or even written a similar system himself? I’d really appreciate any help I can get.

:bust_in_silhouette: Reply From: alwaysbharat

The game saves constantly, but death isn’t really a fail state. You don’t load your saved game when you respawn, you basically just get teleported to the last bonfire you rested at. Try not to think of death as a game over, it’s more like you’re just getting pushed back a bit to try and do better next time

If you pick up an item and then die, that item will still be in your inventory when you respawn, and used items will still be used when you respawn.

It’s easiest to just forget that saving and loading exists at all since it’s 100% for quitting the game and starting again later. There’s no manually saving or loading either, so if you kill an NPC, that NPC is dead and there’s no going back
visit for more: Always Bharat

Interesting. I never thought about it that way.
Still, if I kill an npc or change my position, this needs to be made persistent somehow, because if the player quits the game to resume it later on, it needs to continue, where he left of. So yes, for the death state I have no save/ load issues, but on startup they remain.

Ciavarie | 2020-10-11 23:33

:bust_in_silhouette: Reply From: Asthmar

Save the variables to a dictionary json and when you load the game, update your variables. This works better if your variables are global (singletons). For the player’s position, make a function that when the save button is clicked the function gets the current scene and the player xy values and saves them to a dictionary.

So having a global dictionary used to hold all the things you want to save would be a good idea.

These videos are really helpful and helped me when I made my save system:

how to save and load Json : https://www.youtube.com/watch?v=L9Zekkb4ZXc&t=57s

Code a save system, including saving player position : https://www.youtube.com/watch?v=XQptE6qrhKA

Advanced saving : https://www.youtube.com/watch?v=FjUZgt8lu2g

There won’t be a save button.
The player closes the game at any time he wants and the game still loads where he left off.

I will look through the links. Thank you.

Ciavarie | 2020-10-11 23:30

What if you make the quit button a save button in disguise? That is if you have a quit button.

Asthmar | 2020-10-12 00:38

There will be a quit button and as you suggested correctly it makes sense to add a save function to it.
Still, if the user quits with alt f4 or the pc freezes and needs a restart, the game shall still resume, where the player left of (or at least close to this state). And (asuming the player knows how to avoid the save) the player cant quit to change a quest decision or anything alike.

Ciavarie | 2020-10-12 16:29