hey i need some help with config files. I want to handle errors caused by changing a value in a config file to non expected data types. This is to prevent someone from changing stuff around and making it so that the game crashes on startup and it can always have a default value. This is what I currently have for checking save files.
func _check_corruption(value : int):
##Clears array that removes non expected keys from save files.
keys_to_remove.clear()
##Checks for incorrect values and non specified keys and handles them.
##TODO Figure out how to handle errors, specifically non expected data types.
for key in temp.get_section_keys("profile"):
match key:
"name":
if not typeof(temp.get_value("profile", key)) == TYPE_STRING || temp.get_value("profile", key) == null :
_fix_corruption(value, key)
push_error("Save file " + str(value) + " name is corrupted!")
"wins":
if not typeof(temp.get_value("profile", key)) == TYPE_INT || temp.get_value("profile", key) == null :
_fix_corruption(value, key)
push_error("Save file " + str(value) + " wins is corrupted!")
_:
keys_to_remove.append(key)
for key in keys_to_remove :
temp.erase_section_key("profile", key)
temp.save(CURRENT_SAVE)
func _fix_corruption(value, key):
##Fixes incorrect values.
if key == "name" :
temp.set_value("profile", "name", "Placeholder")
push_warning("Save file " + str(value) + " name is fixed!")
elif key == "wins":
temp.set_value("profile", "wins", 0)
push_warning("Save file " + str(value) + " wins is fixed!")
print(temp.get_value("profile","wins"))
temp.save(CURRENT_SAVE)