As of right now my game has a periodical auto-save system. However, this system makes it hard to introduce enemies and player deaths. So I want to modify this into a snapshot system. I want to make a script that copies a dictionary, and then stores it for later use. So when the player dies, the game loads the copy, not the most recent save, as that would load them moments before they died, likely causing them to endlessly die on that save.
This snapshot system would be much more stable than directly loading auto-save data. I like that you can close the game, then re-open it to being exactly where you left off, but what if your game glitched and you’re outside the map? Well, in that case you could manually load the game where you decided a safe place to save the game was.
In short, I want to know how I can duplicate a dictionary in the global dict. Right now, I have an options dictionary, and a progress dictionary. I would like to copy the progress dictionary, and then save it into a snapshot dictionary. That would leave me with three dictionaries inside the global dict. The snapshot being loaded, instead of the progress dictionary.
you got your GD, you then save it to a file with the code in my blend and load it with the other code part to use it.
your autosave still saves it to your GD, so you are making a copy this way.
I don’t want to use a different saving system to make a copy. Do you know how I can duplicate an already existing dictionary and save it as a new dictionary? I want to use this duplicate as a backup for when the player dies, so the auto-save data isn’t loaded.
To check that any dictionary exists inside globalDict (you may need to check whether certain dictionaries
exist in globalDict before referencing them):
Thank you. Would issuing the same code again overwrite the data? Such as at a later time in the game, when the snapshot is saved again, would the newer data overwrite the older data?
Also, can I search for a specific dictionary, rather than “anyDictionary”?
Thank you. Would issuing the same code again overwrite the data? Such as at a later time in the game, when the snapshot is saved again, would the newer data overwrite the older data?
You’re welcome! And yes it would, which means if you want to have other snapshot data, you would have to have other dictionaries/other methods for storage.
Also, can I search for a specific dictionary, rather than “anyDictionary”?
I agree with Mirror|rorriM. You need deepcopy() otherwise you get a copied list, but the items refer to exactly the same objects (dependent on the type of the item).