stop counting on game over

Hi how can i trigger stop counting on game over ?

[code]
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
[/code] [import]uid: 225288 topic_id: 36202 reply_id: 336202[/import]

Hi there,

For your line [lua]timer.performWithDelay(1000, getScore, 0)[/lua], try assigning the timer to a variable instead, like this: [lua]scoreTimer = timer.performWithDelay(1000, getScore, 0)[/lua]. Then, after your game over occurs, you could do [lua]timer.cancel(scoreTimer); scoreTimer = nil[/lua] to stop the score from incrementing and release the memory.

Hope this helps!

  • Andrew [import]uid: 109711 topic_id: 36202 reply_id: 143785[/import]

Hi Andrew,

i have done this now and it works

[code]keeping_score = true

if keeping_score then
score = score + 1
end

function restartStopScore()
keeping_score = false
end

function restartContinueScore()
keeping_score = true
end
[/code] [import]uid: 225288 topic_id: 36202 reply_id: 143806[/import]

The problem with that though is that your timer will still be running every second for no real reason. The way provided by Andrew saves you resources overall by stopping the timer. You can do this:

[code]
function keepingScore()
score = score + 1
end

ScoreTimer = timer.performWithDelay( 1000, keepingScore, 0 )

function gameOver()
–code for game over here
timer.cancel( ScoreTimer )
ScoreTimer = nil
end

function restartContinueScore()
if ScoreTimer == nil then
ScoreTimer = timer.performWithDelay( 1000, keepingScore, 0 )
else
return true
end
end
[/code] [import]uid: 77199 topic_id: 36202 reply_id: 143868[/import]

Hi there,

For your line [lua]timer.performWithDelay(1000, getScore, 0)[/lua], try assigning the timer to a variable instead, like this: [lua]scoreTimer = timer.performWithDelay(1000, getScore, 0)[/lua]. Then, after your game over occurs, you could do [lua]timer.cancel(scoreTimer); scoreTimer = nil[/lua] to stop the score from incrementing and release the memory.

Hope this helps!

  • Andrew [import]uid: 109711 topic_id: 36202 reply_id: 143785[/import]

Hi Andrew,

i have done this now and it works

[code]keeping_score = true

if keeping_score then
score = score + 1
end

function restartStopScore()
keeping_score = false
end

function restartContinueScore()
keeping_score = true
end
[/code] [import]uid: 225288 topic_id: 36202 reply_id: 143806[/import]

The problem with that though is that your timer will still be running every second for no real reason. The way provided by Andrew saves you resources overall by stopping the timer. You can do this:

[code]
function keepingScore()
score = score + 1
end

ScoreTimer = timer.performWithDelay( 1000, keepingScore, 0 )

function gameOver()
–code for game over here
timer.cancel( ScoreTimer )
ScoreTimer = nil
end

function restartContinueScore()
if ScoreTimer == nil then
ScoreTimer = timer.performWithDelay( 1000, keepingScore, 0 )
else
return true
end
end
[/code] [import]uid: 77199 topic_id: 36202 reply_id: 143868[/import]

Hi there,

For your line [lua]timer.performWithDelay(1000, getScore, 0)[/lua], try assigning the timer to a variable instead, like this: [lua]scoreTimer = timer.performWithDelay(1000, getScore, 0)[/lua]. Then, after your game over occurs, you could do [lua]timer.cancel(scoreTimer); scoreTimer = nil[/lua] to stop the score from incrementing and release the memory.

Hope this helps!

  • Andrew [import]uid: 109711 topic_id: 36202 reply_id: 143785[/import]

Hi Andrew,

i have done this now and it works

[code]keeping_score = true

if keeping_score then
score = score + 1
end

function restartStopScore()
keeping_score = false
end

function restartContinueScore()
keeping_score = true
end
[/code] [import]uid: 225288 topic_id: 36202 reply_id: 143806[/import]

The problem with that though is that your timer will still be running every second for no real reason. The way provided by Andrew saves you resources overall by stopping the timer. You can do this:

[code]
function keepingScore()
score = score + 1
end

ScoreTimer = timer.performWithDelay( 1000, keepingScore, 0 )

function gameOver()
–code for game over here
timer.cancel( ScoreTimer )
ScoreTimer = nil
end

function restartContinueScore()
if ScoreTimer == nil then
ScoreTimer = timer.performWithDelay( 1000, keepingScore, 0 )
else
return true
end
end
[/code] [import]uid: 77199 topic_id: 36202 reply_id: 143868[/import]

Hi there,

For your line [lua]timer.performWithDelay(1000, getScore, 0)[/lua], try assigning the timer to a variable instead, like this: [lua]scoreTimer = timer.performWithDelay(1000, getScore, 0)[/lua]. Then, after your game over occurs, you could do [lua]timer.cancel(scoreTimer); scoreTimer = nil[/lua] to stop the score from incrementing and release the memory.

Hope this helps!

  • Andrew [import]uid: 109711 topic_id: 36202 reply_id: 143785[/import]

Hi Andrew,

i have done this now and it works

[code]keeping_score = true

if keeping_score then
score = score + 1
end

function restartStopScore()
keeping_score = false
end

function restartContinueScore()
keeping_score = true
end
[/code] [import]uid: 225288 topic_id: 36202 reply_id: 143806[/import]

The problem with that though is that your timer will still be running every second for no real reason. The way provided by Andrew saves you resources overall by stopping the timer. You can do this:

[code]
function keepingScore()
score = score + 1
end

ScoreTimer = timer.performWithDelay( 1000, keepingScore, 0 )

function gameOver()
–code for game over here
timer.cancel( ScoreTimer )
ScoreTimer = nil
end

function restartContinueScore()
if ScoreTimer == nil then
ScoreTimer = timer.performWithDelay( 1000, keepingScore, 0 )
else
return true
end
end
[/code] [import]uid: 77199 topic_id: 36202 reply_id: 143868[/import]