0 votes

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.

in Engine by (55 points)

2 Answers

+1 vote
Best answer

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

by (46 points)
selected by

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.

+1 vote

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

by (651 points)

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.

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

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.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.