Hi all, I have this as my save score function:
func configFileSave():
var file_to_save= "res://stats.cfg"
var configFile = ConfigFile.new()
if difficulty == "easy":
configFile.set_value("Scores","totalGamesWonEasy",totalGamesWon)
configFile.set_value("Scores","totalGamesLostEasy",totalGamesLost)
configFile.set_value("Scores","totalGamesTiedEasy",totalGamesTied)
configFile.save(file_to_save)
print("TotalgamesTied SaveFile: ", totalGamesTied)
elif difficulty == "medium":
configFile.set_value("Scores","totalGamesWonMedium",totalGamesWon)
configFile.set_value("Scores","totalGamesLostMedium",totalGamesLost)
configFile.set_value("Scores","totalGamesTiedMedium",totalGamesTied)
configFile.save(file_to_save)
elif difficulty == "hard":
configFile.set_value("Scores","totalGamesWonHard",totalGamesWon)
configFile.set_value("Scores","totalGamesLostHard",totalGamesLost)
configFile.set_value("Scores","totalGamesTiedHard",totalGamesTied)
configFile.save(file_to_save)
If I'm on hard
setting and the score is created at the end of the game, it all writes just fine. It looks something like this:
[Scores]
totalGamesLostHard=1
totalGamesTiedHard=0
totalGamesWonHard=1
Great stuff. I then swap to say, easy
, and run the game. Unfortunately though, the score gets changed to this:
[Scores]
totalGamesLostEasy=0
totalGamesTiedEasy=0
totalGamesWonEasy=1
Now I would have thought that if I had played on hard, then played on easy, it would then have both in the file, like below (but it doesn't):
[Scores]
totalGamesLostHard=1
totalGamesTiedHard=0
totalGamesWonHard=1
totalGamesLostEasy=0
totalGamesTiedEasy=0
totalGamesWonEasy=1
Can anyone offer some advice as to why it's not appending and why it's re-creating the file and placing new contents each time?
Thanks so much...