1
votes

I'm making a Lua game where when the scene starts, the timer starts increasing numbers for 20 or 30 points every second. What's the code for a timer like that?

Current score count (no count at all, just text)

scoreTxt = display.newText( "Score: 0", 0, 0, "Helvetica", 40 )
scoreTxt:setReferencePoint(display.TopLeftReferencePoint)
scoreTxt.x = display.screenOriginX + 10
scoreTxt.y = display.screenOriginY + 32

so the 'score: 0's number should increase every second...

2

2 Answers

2
votes
local score = 0

local scoreTxt = display.newText( "Score: 0", 0, 0, "Helvetica", 40 )
scoreTxt:setReferencePoint(display.TopLeftReferencePoint)
scoreTxt.x = display.screenOriginX + 10
scoreTxt.y = display.screenOriginY + 32

local function updateScore()
     score = score + 20
     scoreText.text = string.format("Score: %d", score)
end

local scoreTimer = timer.performWithDelay(1000, updateScore, 0)

or something similar.

0
votes

You can use the examples in the corona docs here and see if they can be adapted to your use case.