Timer

i was just playing around with corona trying to get  a timer going but it seems i cant. I’m a complete corona noob so please explain why im getting an error here:

[lua] local tmr = 0
local tmrtext = display.newText(tmr,display.contentWidth*0.5, display.contentHeight*0.5, native.systemFont, 100 )

local function AddToTime(tmr)
    tmr = tmr +1
    tmrtext = tmr
end

local timeadd = timer.performWithDelay(1000, AddToTime,-1)

[/lua]

tmrtext is a corona display object - you want to update the text property of that object rather then it directly:

[lua]

tmrtext.text = tmr

[/lua]

thanks for the help but its giving me this error message: ‘attempt to perform arithmetic on local ‘tmr’ a table value’. Not sure what I’m doing wrong to be honest …

i’ve sorted it out, here is what i came up with

[lua] local tmr = 0

local tmrTxt = display.newText( “0”, display.contentWidth*0.5,display.contentHeight*0.5, native.systemFont, 40 )

local function AddToTime()
     tmr = tmr + 1
     tmrTxt.text = string.format("%d", tmr)
end

local timeadd = timer.performWithDelay(1000, AddToTime, -1)

[/lua]

tmrtext is a corona display object - you want to update the text property of that object rather then it directly:

[lua]

tmrtext.text = tmr

[/lua]

thanks for the help but its giving me this error message: ‘attempt to perform arithmetic on local ‘tmr’ a table value’. Not sure what I’m doing wrong to be honest …

i’ve sorted it out, here is what i came up with

[lua] local tmr = 0

local tmrTxt = display.newText( “0”, display.contentWidth*0.5,display.contentHeight*0.5, native.systemFont, 40 )

local function AddToTime()
     tmr = tmr + 1
     tmrTxt.text = string.format("%d", tmr)
end

local timeadd = timer.performWithDelay(1000, AddToTime, -1)

[/lua]