Score depending on time

Hi!
I’m making a game where you get score as long as you are alive. I’ve made a code that works, but I don’t know if this is the way to do it.

if event.time - timeLastScore \>= 1 then  
 local scoreBall = display.newImage("score.png")  
 scoreBall.x = 1  
 scoreBall.y = 1  
 physics.addBody(scoreBall, "kinematic", {bounce = 0})  
 score = score + 1  
 scoreText.text = score  
 transition.to(scoreBall, {time = 1, x = -1, onComplete = function(self) self.parent:remove(self); self = nil; end})  
 timeLastScore = event.time  
end  

Is there a smarter way to do it?

Best regards,
joelwe [import]uid: 54640 topic_id: 9750 reply_id: 309750[/import]

scoreIncTimer = timer.performWithDelay(1000,incScore,0)

function incScore()
score = score + 10
scoreText.text = score
end

function onDeath()
timer.cancel(scoreIncTimer) --my memory might be bad, check api on how to cancel timers
end [import]uid: 34945 topic_id: 9750 reply_id: 35574[/import]

http://techority.com/2011/03/25/adding-a-score-to-your-app-that-goes-up-based-on-a-timer/

Peach Pellan wrote the tutorial it includes samplecode and everything… works like a charm! [import]uid: 56715 topic_id: 9750 reply_id: 36174[/import]

Thank you guys for your answers! They both work great! :smiley: [import]uid: 54640 topic_id: 9750 reply_id: 36209[/import]