Hey I’ll try to help you, what you want to is the following which is an example:
---This is at startup during game
highscore = loadFile ("highscore.txt")
local points = 0 --Example I'm using this can be anything you want for keeping track of score
--This would go at the bottom of your game.lua or whatever you name it
local function checkForFile ()
if highscore == "empty" then
highscore = 0
saveFile("highscore.txt", highscore)
end
end
checkForFile()
local function onSystemEvent ()
if points \> tonumber(highscore) then
saveFile("highscore.txt", points)
end
end
Runtime:addEventListener( "enterFrame", onSystemEvent )
--Then we save the file before the scene is changed
--The delay scene change is to give time for the file to save
local function dead ()
timer.cancel(tik)
saveFile("score.txt", points)
local function change ()
director:changeScene("gameover", "flip")
end
timer.performWithDelay(1000, change, 1)
end
end
tik = timer.performWithDelay(1000, dead, 0)
Below is at the gameover.lua
--Here you want the call your highscore, and score
highscore = loadFile("highscore.txt")
highscore = highscore
points = loadFile("score.txt")
points = points
--This is to display your highscore
--And regular score if you want
local highscoreDisp = display.newText(highscore, 0, 0, "Arial Black", 20)
highscoreDisp.x = 240
highscoreDisp.y = 140
localGroup:insert(highscoreDisp)
local current = display.newText("", 0,0,"Arial Black", 20)
current.x = 240
current.y = 175
current.text = "Score: ".. points
localGroup:insert(current)
This is how you would save your highscore using Ego. [import]uid: 17058 topic_id: 21037 reply_id: 134345[/import]