save and load game

is there a way to allow a running game (made with Blender) to save its current state?E.g. when the player wants to shut down the game and, later, restart from that point.
I read in the documentation there are Quit/Restart Game Actuators ( restarting the game from the beginning…), but what about “Save/Load”?
If I well understand, “Save bge.logic.globalDict” is used to save only some game properties…
Thanks and kind regards.

do a search in the “Resources” forum, there’s plenty of threads and solutions about that topic.

If I well understand, “Save bge.logic.globalDict” is used to save only some game properties…
afaik is the unique thing you can, integers, strings, and stuff like save vectors or matrices you have to unpack it in tuples.(or list)to save the “target” or stuff like this no way

import bge , json

gd = bge.logic.globalDict

## suppose these are written durin the game ##

gd["player_position"] = (11,55,0)
data = gd.copy()


#with open(bge.logic.expandPath("//save_game.txt"), "w") as f:
#    json.dump(data,f,indent=True)
with open(bge.logic.expandPath("//save_game.txt"), "w") as f:
# in the folder should be a file save_game.txt
# it is perfectly readable also
# warning to use ever -> bge.logic.expandPath("//save_game.txt")
# otherwise it can save wathewher


import bge , json

gd = bge.logic.globalDict

with open(bge.logic.expandPath("//save_game.txt"), "r") as f:
    data = json.load(f)

gd = data
print(gd["money"])# 22

Thx Marco, I’ll try that out. :slight_smile:

In addition to Marcos answer;

There’s a save/load script written by Cotax in resources that will save properties, and also object locations. So if you wanted your player, or some other object to be where it was when you quit, this script will do it. It’s not hard to set it up, the instruction are clear.
I use it all the time. (To save) I change the “S” sensor, to a message “saveme” and (To load) the “L” sensor to message “loadme”. But there are other scripts in resources that will do the same.