Saving data with Director class

Hello

Can anyone help me figure this out?

I have been looking at the Save Table demo and have added it to a game using the Director class to try create a high score table.

Currently, when the user gets a score, the game writes it to a file. But when the user goes back to play the level again, it overwrites the score, even if it’s lower than the last time they played it. I only want the score to be updated if it’s higher than the number already saved.

Obviously it’s easy, but I can’t figure it out.

I can upload the code to my site, or email it to anyone who wants to have a look.

Thanks in advance!

Steve [import]uid: 45932 topic_id: 8435 reply_id: 308435[/import]

You need to load the score that is stored in the file. Then save it to a variable then check it against the new score and only save back to the file if it is greater than the old score. [import]uid: 11809 topic_id: 8435 reply_id: 30226[/import]

Thanks for your reply iDev.

I guessed this is the case but I’m still learning this so I’m not sure hope to implement it.

At the moment, I’ve simplified the code to get it to work, so is this how it should work?

At the first time of playing, currentScore = 0, highScore = 0

when the user presses a button, currentScore = currentScore + 20.

When the game is over

local function updateScore  
 if currentScore is \< highScore then  
 highScore = currentScore  
 saveData()  
 elseif currentScore \>= highScore  
 tell it to do nothing?  
 end  
end  

Is this right?
[import]uid: 45932 topic_id: 8435 reply_id: 30292[/import]

Here’s what I used for my game:

–Load External Libraries
require “sqlite3”

–Variables
local topScore
local currentScore

–Get Top Score
local getTopScore = function()
–Get topScore from the Sqlite Database and store it in topScore
end

–Save Top Score
local saveTopScore = function()
–Save topScore to the Sqlite Database
end

local win = function()
if currentScore > topScore then
topScore = currentScore
saveTopScore()
end
end

Hope this helps you out. Be sure to call the getTopScore before the game starts. [import]uid: 11809 topic_id: 8435 reply_id: 30295[/import]

Thanks iDev. I’ll have a look at this tonight. [import]uid: 45932 topic_id: 8435 reply_id: 30305[/import]