local function addtoit (event)
if event.phase == “ended” then
score.setScore (score.getScore()+107)
end
end
background:addEventListener(“touch”, addtoit) [/code]
Ok In the code above demonstrates how to add score. Now I want to know how to save the score when I exit the app, or touching a button to save a score if one is greater than the other.
So basically save a score only if the score is greater.
That tutorial is really useful, thanks for sharing. Could a similar this be used to lock levels until the previous level is completed? I’ve tried to use ice but I just don’t understand it! [import]uid: 116264 topic_id: 21037 reply_id: 83312[/import]
@Sebitttas - You would load the score just like you do in that tutorial, except rather than simply printing it in the terminal you’d display it on the screen. (Just do new text, eg; myText, then do myText.text = loadedScore - or whatever you called the highscore when you loaded it.)
@peach also another thing the high score website you gave me. I get an error saying expected then near ‘&’ and I’m trying to figure it out. What is the solution to that [import]uid: 17058 topic_id: 21037 reply_id: 83358[/import]
I was trying to do that and still nothing, even though there is already a then still nothing
[import]uid: 17058 topic_id: 21037 reply_id: 83512[/import]
@peach oh I did not know it changed the symbol. I was looking over it a lot I did not know the symbol changed, I thought that meant like saving. I’am you know a beginner so I’m still learning how to figure theses stuff. But thanks for clearing it out for me [import]uid: 17058 topic_id: 21037 reply_id: 83589[/import]
Thanks very much for you tutorial on how to lock levels, it has helped so much! I have one question about it - will it still remember the currentLevel.txt value after an update from the market? [import]uid: 116264 topic_id: 21037 reply_id: 83594[/import]
@willjhoward um I would not really know. I just sent the game. Also working on the update for the new game. I would tell you after the update of my new game to see how it goes [import]uid: 17058 topic_id: 21037 reply_id: 83597[/import]
saved documents should remain intact when updating an app but if app is removed then reinstalled it will not [import]uid: 7911 topic_id: 21037 reply_id: 83599[/import]
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?
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]