I’m using 4.7.2
Question
I’m trying to remake fnaf world in godot as a fun way of learning and am having some really annoying issues with saving.
basically, I can’t find a good way of resetting the save file and data persists from the existing save file before trying to reset it.
currently, I am setting a “clean save file” Dictionary at the complete start of the game to reset the save file, this is just the save_dict without any changes applied to it
#this happens in the first scene of the game to just set the clean save file
func _ready() -> void:
Globals.cleansavefile = SaveLoad.SAVE_DICT
#cleansavefile is defined in a global script:
var cleansavefile: Dictionary
#and "SAVE_DICT" is defined in the SaveLoad global script:
var SAVE_DICT: Dictionary = {}
#the save file is pretty long so I didn't put the contents of it in here, I know for a fact that the actual dict isn't the issue because it would throw an error I feel like if it was.
actually loading the save files aren’t an issue but weirdly trying to reset it leads to the game still reading the save file like it never got reset.
here is how the save and load functions work and how I am trying to reset the data
#how I'm trying to reset it:
func _on_yes_pressed() -> void:
if Globals.menubtnselected == "":
SaveLoad.SAVE_DICT = Globals.cleansavefile
SaveLoad._save(Globals.save_selected)
#rest of the code isn't important as it's just the button doing an animation
#save and load functions:
func _save(save) -> void:
var file: FileAccess = FileAccess.open(save, FileAccess.WRITE)
file.store_var(SAVE_DICT)
file.close()
func _load(save) -> void:
if FileAccess.file_exists(save):
Globals[save] = true
var file: FileAccess = FileAccess.open(save, FileAccess.READ)
var data: Dictionary = file.get_var()
for i in data:
if SAVE_DICT.has(i):
SAVE_DICT[i] = data[i]
file.close()
else:
Globals[save] = false
#the save files are defined like this
const save1: String = "./fwsave1.json"
const save2: String = "./fwsave2.json"
const save3: String = "./fwsave3.json"
the only way I’ve found to actually reset the save file and make it read the clean save is by going to where the game’s exe is and deleting the save file. (that weirdly isn’t a .json file? and just is a “file”)
if anyone knows how I could fix this I would be really grateful <3
I’ll give more information if needed.