Hi all,
I have an issue where when I load a cfg file, it loads the wrong data it seems.
This is the file contents before I run the game:
[Scores]
totalGamesLost=0
totalGamesTied=0
totalGamesWon=0
Inside my globals file I start off like this:
var totalGamesWon = 0
So within my script if I were to look at globals.totalGamesWon
I would get a 0
on immediate startup.
The VERY first thing I do when I load the game is as such:
func _ready():
configFileLoad()
Here is that function:
func configFileLoad():
var fileToLoad= "user://stats.cfg" # Path to save file
var configFile= ConfigFile.new() # Initiate ConfigFile
configFile.load(fileToLoad) # Load file
var err = configFile.load(fileToLoad)
if err == OK:
###########################################
# This first section for totalGamesWon loading a "2"! BUG BUG BUG Why?
###########################################
if (configFile.has_section_key("Scores", "totalGamesWon")):
globals.totalGamesWon = configFile.get_value("Scores", "totalGamesWon")
print("loaded totalGamesWon: ", globals.totalGamesWon)
if (configFile.has_section_key("Scores", "totalGamesLost")):
globals.totalGamesLost = configFile.get_value("Scores", "totalGamesLost")
print("loaded totalGamesLost: ", globals.totalGamesLost)
if (configFile.has_section_key("Scores", "totalGamesTied")):
globals.totalGamesTied = configFile.get_value("Scores", "totalGamesTied")
print("loaded totalGamesTied: ", globals.totalGamesTied)
... and finally, looking at the above 3 x print statements I get this:
loaded totalGamesWon: 2
loaded totalGamesLost: 0
loaded totalGamesTied: 0
I can't for the life of me figure this out. I've checked, double checked, tripple checked. I really hope it's something simple that I'm missing. Any help GREATLY appreciated.