– Highscore
local function save( event ) – function to save score
local path = system.pathForFile( “Highscore.txt”, system.DocumentsDirectory ) – where the file will be saved
local file = io.open( path, “w+b” ) – opening the file
file:write(Highscore …"") – writing the variable ‘score’ in the score.txt file
io.close( file ) – closing the file
– Saves our data
end
local function resumeStart()
local path = system.pathForFile( “Highscore.txt”, system.DocumentsDirectory ) – where the file will be saved
local file = io.open( path, “r” ) – opens the file under the variable file
if file then – if there is a file then
local contents = file:read( “*a” ) – read the contents of the file, and read the whole string(*a)
local prevState = explode(", ", contents) – put the contents of score.txt into a table
print(‘file’)
Highscore = prevState[1] – read the table at position 1 and assign the variable score
io.close( file ) – close file
else – if there is no file
Highscore=0 – the score then starts at 0
end
end
–ANSCA sample code–
function explode(div,str)
if (div==’’) then return false end
local pos,arr = 0,{}
– for each divider found
for st,sp in function() return string.find(str,div,pos,true) end do
table.insert(arr,string.sub(str,pos,st-1)) – Attach chars left of current divider
pos = sp + 1 – Jump past current divider
end
table.insert(arr,string.sub(str,pos)) – Attach chars right of last divider
return arr
end
–ANSCA sample code^–
resumeStart() – call the starting function
local scoretext = display.newText(‘Highscore:’,258,60,native.systemFont,20)
scoretext:rotate(90)
local t = display.newText(’’,258,80,native.systemFont,20) – score text
t.text=Highscore – update t to the score
save() – calls save, so when the user reloads the application the score is still there
t.text=Highscore – updates t to reflect new score
THis is what I have so far but it is not working properly, not showing the highest scoremade, is there something missing? [import]uid: 71568 topic_id: 13051 reply_id: 48855[/import]