Is it possible to create more than 1 save file using the globalDict? In many older games, it was possible to have 3 save slots. So obviously, how would one go about implementing a system where you can “split” the globalDict into three seperate save slots, and how to copy/delete them while the game is running?
I am not meaning to make more than 1 bgeconf file here, the file is one bgeconf file, but has two or more “save slots” where the save data is written to, while configuration, options etc stays global.
That save is selected by a script (save can be named whatever you want)
The script loads everything thats in the save (options stay global across all files).
Should no data be found in a save, the game asks you to create a new save. This writes data to the saves respective slot. The game will not ask you to create a new save on starting, instead it is upon clicking the empty file.
If the user wishes to, they can ‘erase’ the save by clicking the Delete button, which brings up a prompt confirming deletion. This “deletion” actually resets the save by setting it to ‘’ or using del in Python.
How can this all be put into Python?
There is also a problem with Collection actuators. Try adding an overlay collection, and it will either not find the camera you want it to be (must be same camera as same collection) or it will say that the “collection is not found”. Even if you get past all these, the added collection may be invisible and not work. I think this may be a bug.
def saveGame(obj, saveFile):
if "playerData" not in obj:
obj["playerData"] = {}
if "globalTime" not in obj:
obj["globalTime"] = 2.00
writeSave = {
"playerData": obj["playerData"],
"globalTime": obj["globalTime"]
}
jsonData = json.dumps(writeSave)
with open(saveFile, 'w') as outfile:
outfile.write(jsonData)
# I think you can also do json.dump(writeSave, outfile)
# I had to modify my script a lil since I use the orjson lib in my game
For save slots, I would use multiple different files so like slot_1.txt, slot_2.txt, …
Then to load from a specific slot you can just append the number to the name
# Load game data into data object from save file
def loadGameData(obj):
saveFile = f"{getSaveDir()}slot_{obj['saveSlot']}.txt"
if os.path.isfile(saveFile):
with open(saveFile, 'r') as openfile:
data = json.loads(openfile.read())
for key in data:
obj[key] = data[key]
# If no save file exists at that location, make a default one
else:
saveGame(obj, saveFile)
loadGameData(obj)
The problem with this setup, is that I want to be able to store variables inside the save slots (my save slots are named file_1, file_2, file_3).
With a custom module, I can return the save file number for an active save slot when the user clicks on a save file object with an integer property. This is done by assigning the integer property (1 to 3) to its respective slot which is used to retrieve the save file. Now the issue is to load from/save to it. I know you would need to convert the save list to a dictionary since they are now a list stored inside a dictionary.
How can I convert the save slot(s) so I can save to/load from the save slots? Can you please help me on how to convert the save slot so it is a dictionary rather than a list so that I can use items() on it?
For example, I would like to load/save data from slot 1, but you cannot load from a list, it must be converted into a dictionary for use with globalDict.
Sorry if I was slightly confusing here. Edited to be more clear.