How Can I do a timer?

Hi there,

I  would like to introduce a timer in my game, to the player know what time is doing.

The timer would be like this, 00:00:00 (Minutes/Seconds/Tenths).

I see the os.time function, but I don´t know how to use it.

And, when the timer finish, I would like to save in .txt file, to show Scores in my game.

How can I do this?

Goodbye!

well for me this is what I did to my program… although what I’m using is timer.performWithDelay and not os.time() :frowning:
NOTE: you need to use os.time() so that it would be accurate to the time of the phone, you can use this code as an idea on how to create a simple timer, you can improve this code if you want :smiley:

[lua]local minuteHandler = 1
local secondHandler = 0
local milliHandler = 0
local updateClock
local textHolder
local text

minuteHandler = 1
secondHandler = 0
milliHandler = 0

textHolder = minuteHandler…":"…secondHandler…milliHandler;
text = display.newText( textHolder, 0, 0, native.systemFontBold, 32)
text:setTextColor(255,255,255)
text:setReferencePoint(display.TopCenterReferencePoint)
text.x = 100
text.y = 100

updateClock = function( event )
if(minuteHandler ~= 0 or secondHandler ~= 0 or milliHandler ~= 0)then
if(secondHandler == 0 and milliHandler == 0 and minuteHandler ~= 0)then
minuteHandler = minuteHandler - 1
end
if(secondHandler == 0 and milliHandler == 0)then
secondHandler = 6
elseif(secondHandler == 0 and milliHandler > 0) then
secondHandler = 0
end
if(milliHandler == 0) then
milliHandler = 10
end
if(milliHandler > 0)then
milliHandler = milliHandler - 1
if(milliHandler == 9)then
secondHandler = secondHandler - 1
end
end

end
text.text = minuteHandler…":"…secondHandler…milliHandler;
end
timer.performWithDelay(1000, updateClock, 0)[/lua]

Thank you very much!!!

well for me this is what I did to my program… although what I’m using is timer.performWithDelay and not os.time() :frowning:
NOTE: you need to use os.time() so that it would be accurate to the time of the phone, you can use this code as an idea on how to create a simple timer, you can improve this code if you want :smiley:

[lua]local minuteHandler = 1
local secondHandler = 0
local milliHandler = 0
local updateClock
local textHolder
local text

minuteHandler = 1
secondHandler = 0
milliHandler = 0

textHolder = minuteHandler…":"…secondHandler…milliHandler;
text = display.newText( textHolder, 0, 0, native.systemFontBold, 32)
text:setTextColor(255,255,255)
text:setReferencePoint(display.TopCenterReferencePoint)
text.x = 100
text.y = 100

updateClock = function( event )
if(minuteHandler ~= 0 or secondHandler ~= 0 or milliHandler ~= 0)then
if(secondHandler == 0 and milliHandler == 0 and minuteHandler ~= 0)then
minuteHandler = minuteHandler - 1
end
if(secondHandler == 0 and milliHandler == 0)then
secondHandler = 6
elseif(secondHandler == 0 and milliHandler > 0) then
secondHandler = 0
end
if(milliHandler == 0) then
milliHandler = 10
end
if(milliHandler > 0)then
milliHandler = milliHandler - 1
if(milliHandler == 9)then
secondHandler = secondHandler - 1
end
end

end
text.text = minuteHandler…":"…secondHandler…milliHandler;
end
timer.performWithDelay(1000, updateClock, 0)[/lua]

Thank you very much!!!