Ending a game

I basically have a modified 2 minute countdown timer from Peaches timer script. My problem is it keeps counting past 0, when I want the game to end. I know it sounds pretty n00bish but I haven’t found any useful tutorials for this, if it deserves one but I don’t know how to end games!

[code]
local secsText = 0
local minsText = 2

local timeText = display.newText(minsText… “:0” …secsText, 50, 200, “Helvetica”, 24)
timeText:setTextColor(255,255,255)
local function updateTime(event)
secsText = secsText - 1

if secsText < 0 then
secsText = 59
minsText = minsText-1
end

if secsText < 10 then
timeText.text = minsText … “:0” …secsText
else
timeText.text = minsText … “:” …secsText
end

end
timer.performWithDelay(1000, updateTime, 0) [import]uid: 114389 topic_id: 23578 reply_id: 323578[/import]

Don’t forget your check for MinsText being 0 as well as your secsText! :wink: [import]uid: 21331 topic_id: 23578 reply_id: 94552[/import]

Just a quick hint to help stop the counter going passed 0, probably not the best way, but something to consider.

[code]local function updateTime(event)
secsText = secsText - 1

if secsText < 0 and minsText > 0 then
secsText = 59
minsText = minsText-1
end

if minsText < 0 then
minsText = 0
end
if secsText < 0 then
secsText = 0
end

if secsText < 10 then
timeText.text = minsText … “:0” …secsText
else
timeText.text = minsText … “:” …secsText
end
end [/code] [import]uid: 114931 topic_id: 23578 reply_id: 94720[/import]

Oh that’s perfect, thank you! To have the game end when the timer runs out, would I put the timer function in a gameOver function? [import]uid: 114389 topic_id: 23578 reply_id: 94860[/import]