Godot Version
4.2
Question
#Autoload Script
extends Node
var config_file = ConfigFile.new()
var highscore = 0
func load_score():
config_file.load(path)
#auto in this case refers to the autoload itself
auto.highscore = config_file.get_value("try", "highscore", 0)
func save_score():
config_file.set_value("try", "highscore", auto.highscore)
config_file.save("user://hello.cfg")
I would please like to ask about why this code is not working.
You see I start my game with my first scene loading my highscore (using load_score function inside the autoload script which uses a ConfigFile instance/config_file) and that works fine.
But then the problem rises when later in another scene I call the save_score function from the autoload script which saves my highscore as planned except it deletes the other things in the .cfg and only leaves the highscore.
The problem here is that why is it not only updating the highscore and leaving the other things in the .cfg file without having to delete them since config_file was declared globally in the autoload script and should not be forgetting what it is holding through scenes.
(One thing to remember is that each time a function is called it is not called in the autoload script but called in another script, example: auto.save_score() in a script of the current scene)