Reputation: 851
i like to have a trigger to stop counting the score when an event happens,
function restartStopScore()
score = score + 0
end
will not work
score = 0
local scoreText = display.newText( "Score: " .. score, 20, 20,nil, 40)
scoreText:setTextColor(255,255,255)
local function getScore() -- increments Speed value every time it is called
score = score + 1
scoreText.text = "Score: " .. score
print("score" .. score)
end
timer.performWithDelay(1000, getScore, 0)
function restartScore()
--reset the score
score = 0
end
timer.performWithDelay(5000, restartScore, 1)--test trigger reset the score
Upvotes: 2
Views: 580
Reputation: 702
You're going to want to set a boolean variable (true/false) for when you want to keep score. Initialize keeping_score at the top.
keeping_score = true
Wrap your score incrementing with this:
if keeping_score then
score = score + 1
end
And your start/stop functions will look something like this:
function restartStopScore()
keeping_score = false
end
function restartContinueScore()
keeping_score = true
end
Upvotes: 5