Timer?

How can i display a timer on the screen?

You cannot display timer because it code object. What you can do is to display some value as string on screen. So you must create timer, display text and some variable to keep value of time. Next you set .text property of display text to ‘0’ and variable to 0.

Now you should have ‘0’ displayed on sceen. Now we begin to count. You create timer (probably infinite) which each time will increase variable by some amount. You take value of variable and convert it to string with tostring() and update .text of display text with this string.

 how can i divide the minutes from the seconds?

W = display.contentWidth H = display.contentHeight   number = 0   local txtTimer = display.newText( number, 0, 0, "arial", 50 ) txtTimer.x = W/2 txtTimer.y = H/2   function time() number = number + 1 txtTimer.text = number end timer.performWithDelay(1000, time, 0)

You cannot do .text = number! Right side must be of string type so must be .text = tostring(number).

‘Divide minutes from seconds’ - what’s that? You want to have amount of minutes from value in seconds? Then divide number of second by amount of seconds in minute

How can i pause and resume the timer?

Have you ever looked at documentation? If not then always check there first.

[lua]

local timerId

local timerTime = 1

local function updateTimer( event )

  timerTime = timerTime + 1

  local f = os.date( “%M:%S”, timerTime )

  print( f )

end

timerId = timer.performWithDelay( 1000, updateTimer, 0 )

[/lua]

[lua]–Pause

timer.pause( timerId )[/lua]

[lua]–Resume

timer.resume( timerId )[/lua]

Sorry but i can’t stop the timer!

local timer = timer.performWithDelay(1000, time, 0)     local rect = display.newRect(0, 0, 100, 100)   local function pausa( event )     local phase = event.phase        if "ended" == phase then         print( "You pressed  the button!" )        timer.pause()                       end end     rect:addEventListener("touch",pausa)  

You cannot have variable called ‘timer’! If you do so you destroy(lose) corona’s timers for good.

Corona + Lua has set of keywords and variables you are forbidden using or modifying.

In my haste, I provided uncompleted code above.  I’ve made edits to the original post:

[lua]

local timerId

local timerTime = 1

local function updateTimer( event )

  timerTime = timerTime + 1

  local f = os.date( “%M:%S”, timerTime )

  print( f )

end

timerId = timer.performWithDelay( 1000, updateTimer, 0 )

[/lua]

[lua]–Pause

timer.pause( timerId )[/lua]

[lua]–Resume

timer.resume( timerId )[/lua]

My apologies for that.

@piotrz55: You can have a variable named “timer” and not break the global timer, depending on the scope of the variable, but it’s tricky and probably not something to do unless you’re keen on scope.

Cheers.

and how can i   blink the rect??

local rect = display.newRect(0, 0, 100, 100) transition.blink( rect, { time=1000 } )  

@develephant
In whatever scope you override one of Corona’s library then generaly in this scope library becomes corrupted or fails to work. It’s better not to give beginners such subtele niuanses because it’ll easly create confusion and bad habits at such level.
He overrode timer and timer.pause() will no longer work.

Gallonero.at - what Corona build you use? Free version?

How can i display the hundredths of a seconds?

Free version!

How can i display the hundredths of a seconds?

Just like normal text.

Free version!

Then there is no transition.blink() function

How many hundredths is one millisecond?

Just saying… www.google.com

Helppppp!!! My timer is toooo slow??? Where is the error?