I’ve read this post https://coronalabs.com/blog/2013/12/10/tutorial-howtosavescores/ but unluckily I can’t make it works, the score can’t be saved or loaded, txt file is always empty. When I play the app on my phone it’s the same. Then I tried this code from QuizMaster in this topic https://forums.coronalabs.com/topic/58147-help-creating-a-score-counter-and-saving-highscore/ and same result.
So my problems are:
-
the high score can’t be saved/loaded from txt file
-
When I replaythe game, set score to 0, then get the score again to display in gameover scene, but the score is always equal to high score… :wacko:
here is the code in gameover scene:
local highScore \_path = system.pathForFile( "highScore.txt", system.DocumentsDirectory ) \_file = io.open( \_path, "r" ) for line in \_file:lines() do highScore = tonumber (line) end io.close( \_file ) \_file = nil \_path = nil local currentScore=score.get() if currentScore \> highScore then highScore = currentScore \_path = system.pathForFile( "highScore.txt", system.DocumentsDirectory ) \_file = io.open( \_path, "w" ) \_file:write( highScore ) io.close( \_file ) \_file = nil \_path = nil end local function toGamescr() local gsound = audio.loadSound("btnsound.mp3") local psound = audio.play(gsound) composer.gotoScene("restart","crossFade", 300) return true end local function toGamescr0() local gsound = audio.loadSound("btnsound.mp3") local psound = audio.play(gsound) score.set(0) composer.gotoScene("restart","crossFade", 300) return true end
restart scene only has function to check which stage to restart to.
in game scene, whenever the score is added, I saved it. I used one of the two methods I mentioned above but it didn’t work so now I tried both of them, have the scorefile.txt and highScore.txt, I want to compare the score from both of them but nothing works… I’m totally confused, please help me about this.

problem solved.