I followed the guidelines here: http://docs.coronalabs.com/guide/data/readWriteFiles/index.html
Below is my code, basically it works exactly as I expect until I restart the device. I have a ‘score’ table.
score[1] is the current score, and score[2] is the ‘high’ score.
I’m testing on device, and everything works, but when I restart my device, the score[2] defaults back to 0.
Is the save file being deleted on restart? I have it in the “system.DocumentsDirectory” which states in the CoronaSDK documents that these files should reside for the life of the App.
I’m testing on an iphone5 ios8… Below is the actual code for the whole saving and loading high score. It works fine until I restart then the high score ( score[2] ) gets erased/gone.
local function bestScoreLoadSave()
if ( filePath ) then
local path = system.pathForFile( “myfile.txt” , system.DocumentsDirectory )
filePath = io.open( filePath, “r” )
local savedData = file:read( “*a” )
io.close( file )
file = nil
score[2] = tonumber(savedData)
end
if score[2] == nil then
score[2] = 0
end
if score[2] < score[1] then
score[2] = score[1]
local saveData = tostring(score[2])
local path = system.pathForFile( “myfile.txt” , system.DocumentsDirectory )
local file = io.open( path, “w” )
file:write( saveData )
io.close( file )
file = nil
end
end
bestScoreLoadSave()
Why is the high score being reset when the device resets?
Thanks