Hi Tomas,
I am sorry I forgot to mention that I actually am using a file in System.DocumentsDirectory to save scores.
The code I am using is
local M = {} -- Create the local module table (this will hold our functions and data) M.score = 0 M.filename = "score.txt" function M.set( value ) M.score = value M.scoreText = string.format( "% 6d", M.score ) end function M.get() return M.score end function M.add( amount ) M.score = M.score + amount M.scoreText = string.format( "% 6d" , M.score ) end function M.save() local path = system.pathForFile( M.filename, system.DocumentsDirectory ) local file = io.open(path, "w") if ( file ) then local contents = tostring( M.score ) file:write( contents ) io.close( file ) return true else print( "Error: could not read ", M.filename, "." ) return false end end function M.load() local path = system.pathForFile( M.filename, system.DocumentsDirectory ) local contents = "" local file = io.open( path, "r" ) if ( file ) then -- Read all contents of file into a string local contents = file:read( "\*a" ) local score = tonumber(contents); io.close( file ) return score else print( "Error: could not read scores from ", M.filename, "." ) end return nil end return M
That is the code provided in the tutorial. However, force quitting the app using task manager or ‘Force Stop’ in settings takes the scores back to 0, as if the app has been launched for very first time.
So I was wondering what method could be implemented so scores aren’t lost in the event of a forced stop.
Thank you.