After searching through forums I found a way to store the highscore… except the highscore goes back to zero after program exit.
highscore.txt has 0 in it
in main lua:
local highScore
_path = system.pathForFile( “highScore.txt”, system.ResourceDirectory )
_file = io.open( _path, “r” )
for line in _file:lines() do
highScore = tonumber (line)
end
io.close( _file )
_file = nil
_path = nil
_path = system.pathForFile( “highScore.txt”, system.DocumentsDirectory )
_file = io.open( _path, “w” )
_file:write( highScore )
io.close( _file )
_file = nil
_path = nil
At the top of game lua
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
after game over:
if score > highScore then
highScore = score
_path = system.pathForFile( “highScore.txt”, system.DocumentsDirectory )
_file = io.open( _path, “w” )
_file:write( highScore )
io.close( _file )
_file = nil
_path = nil
end