I have been working on having my game track the top 5 high scores. It works great on iOS but most of the time it goes back to the home screen on Android. I am thinking maybe there is a better way to do what I am doing.
Right now I have it read and write to a separate file for each variable. So there is a file for all 5 names and all 5 scores. I would like to have a file that contains just the name and score for each player.
example: John Does 12500
Here is some code I was messing with.
local path = system.pathForFile( “name1.txt”, system.DocumentsDirectory )
local file = io.open( path, “r” )
if file then
local data = file:read("*a")
player1=data
io.close( file )
else
file = io.open( path, “w” )
file:write( player1, " “,highscore1,”\n" )
io.close( file )
end
The part with file:write( player1, " “,highscore1,”\n" ) works as far as writing 2 variables into the file, but I do not know how I could read them when needed and have it put the contents back into those variable.
Any help would be much appreciated. A little tough learning a new language and new APIs at the same time, but I have learned a lot in the last month.
Thanks in advance. [import]uid: 8533 topic_id: 5528 reply_id: 305528[/import]