Saving Score?

Hey

Thanks for the response. I have another question; can the high score be displayed if it occurs at any moment? Also, i sort of understood from your email that this was the way to save score using ego; does that mean you use a different system?

regards [import]uid: 23812 topic_id: 21037 reply_id: 134355[/import]

For your first question yes Highscore can be displayed anywere the only thing you would just have to call is this part:

highscore = loadFile("highscore.txt")  
highscore = highscore  
  
--Below is to display highscore in text  
local highscoreDisp = display.newText(highscore, 0, 0, "Arial Black", 20)  
highscoreDisp.x = 240  
highscoreDisp.y = 140  
localGroup:insert(highscoreDisp)  

For your second question no this the only method I use for saving highscore. [import]uid: 17058 topic_id: 21037 reply_id: 134362[/import]

Hey Peach

I was trying to implement your system of loading high scores, but how do i go about saving the high score as i proceed after completion of a level instead of saving the score upon exiting the app?

regards [import]uid: 23812 topic_id: 21037 reply_id: 134342[/import]

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]

Hey

Thanks for the response. I have another question; can the high score be displayed if it occurs at any moment? Also, i sort of understood from your email that this was the way to save score using ego; does that mean you use a different system?

regards [import]uid: 23812 topic_id: 21037 reply_id: 134355[/import]

For your first question yes Highscore can be displayed anywere the only thing you would just have to call is this part:

highscore = loadFile("highscore.txt")  
highscore = highscore  
  
--Below is to display highscore in text  
local highscoreDisp = display.newText(highscore, 0, 0, "Arial Black", 20)  
highscoreDisp.x = 240  
highscoreDisp.y = 140  
localGroup:insert(highscoreDisp)  

For your second question no this the only method I use for saving highscore. [import]uid: 17058 topic_id: 21037 reply_id: 134362[/import]