A simple "timer" question.

I’m a Corona newbie.

recently, i try to add a “record time” function in “timer app”.

but it cann’t record any time in running.

section code in below, please help me. thank you.

-------------record button function----------- if ( event.target.id == "record" ) then if ( runMode == "record" ) then Record1Button:setlabel("timerText") timerText = event.time Record1Button.text = recordtime recordtime = event.time timer.record( timerID ) timerID = event.time end end end recordButton = widget.newButton( { id = "recordButton", label = "record1", x = display.contentCenterX - 80, y = display.contentHeight - 250, width = 70, height = 32, font = appFont, fontSize = 16, shape = "rectangle", fillColor = { default={ 0.55,0.8,0.125,1 }, over={ 0.66,0.15,0.15,1 } }, labelColor = { default={ 1,1,1,1 }, over={ 1,1,1,1 } }, onRelease = buttonHandler }) mainGroup:insert( recordButton )

I need more details to help you.

Is it normal that you create the button recordButton you change the text of Record1Button?

Add a print above the line 5 to see if the code is execute and to see the value

thanks for remiduchalard’s reply.

i want to catch timertext to change the text of Record1Button.

but i don’t know what to do.

sorry i don’t know very much about how to add  a print above the line 5.

could you show me a sample? thank you so much.

more detail codes in below

-- Button handler function local buttonHandler = function( event ) if ( event.target.id == "pauseResume" ) then if ( runMode == "running" ) then runMode = "paused" pauseResumeButton:setLabel( "Resume" ) pausedAt = event.time timer.pause( timerID ) elseif( runMode == "paused" ) then runMode = "running" pauseResumeButton:setLabel( "Pause" ) timer.resume( timerID ) elseif( runMode == "stopped" ) then runMode = "running" pauseResumeButton:setLabel( "Pause" ) timerText.text = "0.000" timerID = timer.performWithDelay( timeDelay, timerText, timerIterations ) startTime = 0 pausedAt = 0 end elseif ( event.target.id == "cancel" ) then runMode = "stopped" pauseResumeButton:setLabel( "Start" ) timerText.text = "0.000" if ( timerID ) then timer.cancel( timerID ) timerID = nil end startTime = 0 pausedAt = 0 end -------------record button function----------- if ( event.target.id == "record" ) then if ( runMode == "record" ) then Record1Button:setlabel("timerText") timerText = event.time Record1Button.text = recordtime recordtime = event.time timer.record( timerID ) timerID = event.time end end end -- Create buttons pauseResumeButton = widget.newButton( { id = "pauseResume", label = "Start", x = display.contentCenterX, y = display.contentHeight - 100, width = 160, height = 32, font = appFont, fontSize = 16, shape = "rectangle", fillColor = { default={ 0.9,0.37,0.05,1 }, over={ 0.945,0.386,0.053,1 } }, labelColor = { default={ 1,1,1,1 }, over={ 1,1,1,1 } }, onRelease = buttonHandler }) mainGroup:insert( pauseResumeButton ) cancelButton = widget.newButton( { id = "cancel", label = "Cancel", x = display.contentCenterX, y = display.contentHeight - 50, width = 160, height = 32, font = appFont, fontSize = 16, shape = "rectangle", fillColor = { default={ 0.55,0.125,0.125,1 }, over={ 0.66,0.15,0.15,1 } }, labelColor = { default={ 1,1,1,1 }, over={ 1,1,1,1 } }, onRelease = buttonHandler }) mainGroup:insert( cancelButton ) recordButton = widget.newButton( { id = "recordButton", label = "Record", x = display.contentCenterX , y = display.contentHeight - 150, width = 160, height = 32, font = appFont, fontSize = 16, shape = "rectangle", fillColor = { default={ 0.4,0.8,0.125,1 }, over={ 0.66,0.15,0.15,1 } }, labelColor = { default={ 1,1,1,1 }, over={ 1,1,1,1 } }, onRelease = buttonHandler }) mainGroup:insert( recordButton ) recordButton = widget.newButton( { id = "recordButton", label = "record1", x = display.contentCenterX - 80, y = display.contentHeight - 250, width = 70, height = 32, font = appFont, fontSize = 16, shape = "rectangle", fillColor = { default={ 0.55,0.8,0.125,1 }, over={ 0.66,0.15,0.15,1 } }, labelColor = { default={ 1,1,1,1 }, over={ 1,1,1,1 } }, onRelease = buttonHandler }) mainGroup:insert( recordButton )

You have done a little mistake, you change the label of record1button but it didn’t exist you create two button recordbutton (that’s mean one is display but you can’t access to it because when you look a this value it’s contain the second button).

Try this(I can’t try the code)

-- Button handler function local buttonHandler = function( event ) if ( event.target.id == "pauseResume" ) then if ( runMode == "running" ) then runMode = "paused" pauseResumeButton:setLabel( "Resume" ) pausedAt = event.time timer.pause( timerID ) elseif( runMode == "paused" ) then runMode = "running" pauseResumeButton:setLabel( "Pause" ) timer.resume( timerID ) elseif( runMode == "stopped" ) then runMode = "running" pauseResumeButton:setLabel( "Pause" ) timerText.text = "0.000" timerID = timer.performWithDelay( timeDelay, timerText, timerIterations ) startTime = 0 pausedAt = 0 end elseif ( event.target.id == "cancel" ) then runMode = "stopped" pauseResumeButton:setLabel( "Start" ) timerText.text = "0.000" if ( timerID ) then timer.cancel( timerID ) timerID = nil end startTime = 0 pausedAt = 0 end -------------record button function----------- if ( event.target.id == "record" ) then if ( runMode == "record" ) then Record1Button:setlabel(event.time) -- it's a widget and to edit the text you to use this line timerText = event.time --Record1Button.text = recordtime --recordtime = event.time timer.record( timerID ) timerID = event.time end end end -- Create buttons pauseResumeButton = widget.newButton( { id = "pauseResume", label = "Start", x = display.contentCenterX, y = display.contentHeight - 100, width = 160, height = 32, font = appFont, fontSize = 16, shape = "rectangle", fillColor = { default={ 0.9,0.37,0.05,1 }, over={ 0.945,0.386,0.053,1 } }, labelColor = { default={ 1,1,1,1 }, over={ 1,1,1,1 } }, onRelease = buttonHandler }) mainGroup:insert( pauseResumeButton ) cancelButton = widget.newButton( { id = "cancel", label = "Cancel", x = display.contentCenterX, y = display.contentHeight - 50, width = 160, height = 32, font = appFont, fontSize = 16, shape = "rectangle", fillColor = { default={ 0.55,0.125,0.125,1 }, over={ 0.66,0.15,0.15,1 } }, labelColor = { default={ 1,1,1,1 }, over={ 1,1,1,1 } }, onRelease = buttonHandler }) mainGroup:insert( cancelButton ) recordButton = widget.newButton( { id = "recordButton", label = "Record", x = display.contentCenterX , y = display.contentHeight - 150, width = 160, height = 32, font = appFont, fontSize = 16, shape = "rectangle", fillColor = { default={ 0.4,0.8,0.125,1 }, over={ 0.66,0.15,0.15,1 } }, labelColor = { default={ 1,1,1,1 }, over={ 1,1,1,1 } }, onRelease = buttonHandler }) mainGroup:insert( recordButton ) record1Button = widget.newButton(-- you had to object with the same name. You have forgotten the 1 in record1Button { id = "recordButton", label = "record1", x = display.contentCenterX - 80, y = display.contentHeight - 250, width = 70, height = 32, font = appFont, fontSize = 16, shape = "rectangle", fillColor = { default={ 0.55,0.8,0.125,1 }, over={ 0.66,0.15,0.15,1 } }, labelColor = { default={ 1,1,1,1 }, over={ 1,1,1,1 } }, onRelease = buttonHandler }) mainGroup:insert( recordButton )

sorry, i try to fix codes. but not success.

the detail codes in below. thanks for your help.

---------------------- -- BEGIN SAMPLE CODE ---------------------- -- Require libraries/plugins local widget = require( "widget" ) -- Set app font local appFont = sampleUI.appFont -- Set local variables local timeDelay = 5 -- 1/10th of a second ( 1000 milliseconds / 10 = 100 ) local timerIterations = 60000 -- Set the timer limit to 60 seconds ( 600 \* 0.1 = 60 ) local runMode = "stopped" local startTime = 0 local pausedAt = 0 -- Forward references local timerText, pauseResumeButton, cancelButton, recordButton, timerID, recordText -- Called when the app's view has been resized (orientation changed) local function onResize( event ) pauseResumeButton.x = display.contentCenterX pauseResumeButton.y = display.contentHeight - 100 cancelButton.x = display.contentCenterX cancelButton.y = display.contentHeight - 50 timerText.x = display.contentCenterX - 15 end Runtime:addEventListener( "resize", onResize ) -- Button handler function local buttonHandler = function( event ) if ( event.target.id == "pauseResume" ) then if ( runMode == "running" ) then runMode = "paused" pauseResumeButton:setLabel( "Resume" ) pausedAt = event.time timer.pause( timerID ) elseif( runMode == "paused" ) then runMode = "running" pauseResumeButton:setLabel( "Pause" ) timer.resume( timerID ) elseif( runMode == "stopped" ) then runMode = "running" pauseResumeButton:setLabel( "Pause" ) timerText.text = "0.000" timerID = timer.performWithDelay( timeDelay, timerText, timerIterations ) startTime = 0 pausedAt = 0 end elseif ( event.target.id == "cancel" ) then runMode = "stopped" pauseResumeButton:setLabel( "Start" ) timerText.text = "0.000" if ( timerID ) then timer.cancel( timerID ) timerID = nil end startTime = 0 pausedAt = 0 end ------------------------------------------------------------------------------- -- record button function -------------------------------------------------------------------------------- if ( event.target.id == "record" ) then if ( runMode == "record" ) then Record1Button:setlabel(event.time) -- it's a widget and to edit the text you to use this line timerText = event.time --Record1Button.text = recordtime --recordtime = event.time timer.record( timerID ) timerID = event.time end end end -- Create buttons pauseResumeButton = widget.newButton( { id = "pauseResume", label = "Start", x = display.contentCenterX, y = display.contentHeight - 100, width = 160, height = 32, font = appFont, fontSize = 16, shape = "rectangle", fillColor = { default={ 0.9,0.37,0.05,1 }, over={ 0.945,0.386,0.053,1 } }, labelColor = { default={ 1,1,1,1 }, over={ 1,1,1,1 } }, onRelease = buttonHandler }) mainGroup:insert( pauseResumeButton ) cancelButton = widget.newButton( { id = "cancel", label = "Cancel", x = display.contentCenterX, y = display.contentHeight - 50, width = 160, height = 32, font = appFont, fontSize = 16, shape = "rectangle", fillColor = { default={ 0.55,0.125,0.125,1 }, over={ 0.66,0.15,0.15,1 } }, labelColor = { default={ 1,1,1,1 }, over={ 1,1,1,1 } }, onRelease = buttonHandler }) mainGroup:insert( cancelButton ) recordButton = widget.newButton( { id = "recordButton", label = "Record", x = display.contentCenterX , y = display.contentHeight - 150, width = 160, height = 32, font = appFont, fontSize = 16, shape = "rectangle", fillColor = { default={ 0.4,0.8,0.125,1 }, over={ 0.66,0.15,0.15,1 } }, labelColor = { default={ 1,1,1,1 }, over={ 1,1,1,1 } }, onRelease = buttonHandler }) mainGroup:insert( recordButton ) record1Button = widget.newButton( { id = "recordButton", label = "record1", x = display.contentCenterX - 80, y = display.contentHeight - 250, width = 70, height = 32, font = appFont, fontSize = 16, shape = "rectangle", fillColor = { default={ 0.55,0.8,0.125,1 }, over={ 0.66,0.15,0.15,1 } }, labelColor = { default={ 1,1,1,1 }, over={ 1,1,1,1 } }, onRelease = buttonHandler }) mainGroup:insert( recordButton ) record2Button = widget.newButton( { id = "recordButton", label = "record2", x = display.contentCenterX , y = display.contentHeight - 250, width = 70, height = 32, font = appFont, fontSize = 16, shape = "rectangle", fillColor = { default={ 0.55,0.8,0.125,1 }, over={ 0.66,1,1,1 } }, labelColor = { default={ 1,1,1,1 }, over={ 1,1,1,1 } }, onRelease = buttonHandler }) mainGroup:insert( recordButton ) record3Button = widget.newButton( { id = "recordButton", label = "record3", x = display.contentCenterX +80 , y = display.contentHeight - 250, width = 70, height = 32, font = appFont, fontSize = 16, shape = "rectangle", fillColor = { default={ 0.55,0.8,0.125,1 }, over={ 0.66,0.15,0.15,1 } }, labelColor = { default={ 1,1,1,1 }, over={ 1,1,1,1 } }, onRelease = buttonHandler }) mainGroup:insert( recordButton ) -- In order for the right-aligned timer to display nicely, we need a font that has monospaced digits -- Usually this is the system font and we can detect it by measuring the relative widths of the "1" and "2" characters local bestFontForDevice = nil local testText = display.newText( { x=-1000, y=-1000, text="1", font=native.systemFontBold, fontSize=16 } ) local width1 = testText.width testText.text = "2" local width2 = testText.width display.remove( testText ) if ( width2 \> width1 ) then -- The system font doesn't have monospaced digits, so use a font known to have them bestFontForDevice = ( system.getInfo("platform") == "win32" and "Courier New" or "Helvetica Neue" ) else -- The system font has monospaced digits bestFontForDevice = native.systemFontBold end -- Create timer text object timerText = display.newText( { parent=mainGroup, text="0.000", x=display.contentCenterX-15, y=105, width=310, font=bestFontForDevice, fontSize=60, align="right" }) timerText:setFillColor( 0,0.5,1 ) -- Timer function function timerText:timer( event ) if ( startTime == 0 ) then startTime = event.time end if ( pausedAt \> 0 ) then startTime = startTime + ( event.time - pausedAt ) recordtime = startTime + ( event.time - pausedAt ) pausedAt = 0 end self.text = string.format( "%.3f", (event.time - startTime)/1000 ) if ( ( event.time - startTime ) \>= ( timerIterations \* timeDelay ) ) then print( "Resetting timer..." ) buttonHandler( { target={ id="cancel" } } ) end end

I need more details to help you.

Is it normal that you create the button recordButton you change the text of Record1Button?

Add a print above the line 5 to see if the code is execute and to see the value

thanks for remiduchalard’s reply.

i want to catch timertext to change the text of Record1Button.

but i don’t know what to do.

sorry i don’t know very much about how to add  a print above the line 5.

could you show me a sample? thank you so much.

more detail codes in below

-- Button handler function local buttonHandler = function( event ) if ( event.target.id == "pauseResume" ) then if ( runMode == "running" ) then runMode = "paused" pauseResumeButton:setLabel( "Resume" ) pausedAt = event.time timer.pause( timerID ) elseif( runMode == "paused" ) then runMode = "running" pauseResumeButton:setLabel( "Pause" ) timer.resume( timerID ) elseif( runMode == "stopped" ) then runMode = "running" pauseResumeButton:setLabel( "Pause" ) timerText.text = "0.000" timerID = timer.performWithDelay( timeDelay, timerText, timerIterations ) startTime = 0 pausedAt = 0 end elseif ( event.target.id == "cancel" ) then runMode = "stopped" pauseResumeButton:setLabel( "Start" ) timerText.text = "0.000" if ( timerID ) then timer.cancel( timerID ) timerID = nil end startTime = 0 pausedAt = 0 end -------------record button function----------- if ( event.target.id == "record" ) then if ( runMode == "record" ) then Record1Button:setlabel("timerText") timerText = event.time Record1Button.text = recordtime recordtime = event.time timer.record( timerID ) timerID = event.time end end end -- Create buttons pauseResumeButton = widget.newButton( { id = "pauseResume", label = "Start", x = display.contentCenterX, y = display.contentHeight - 100, width = 160, height = 32, font = appFont, fontSize = 16, shape = "rectangle", fillColor = { default={ 0.9,0.37,0.05,1 }, over={ 0.945,0.386,0.053,1 } }, labelColor = { default={ 1,1,1,1 }, over={ 1,1,1,1 } }, onRelease = buttonHandler }) mainGroup:insert( pauseResumeButton ) cancelButton = widget.newButton( { id = "cancel", label = "Cancel", x = display.contentCenterX, y = display.contentHeight - 50, width = 160, height = 32, font = appFont, fontSize = 16, shape = "rectangle", fillColor = { default={ 0.55,0.125,0.125,1 }, over={ 0.66,0.15,0.15,1 } }, labelColor = { default={ 1,1,1,1 }, over={ 1,1,1,1 } }, onRelease = buttonHandler }) mainGroup:insert( cancelButton ) recordButton = widget.newButton( { id = "recordButton", label = "Record", x = display.contentCenterX , y = display.contentHeight - 150, width = 160, height = 32, font = appFont, fontSize = 16, shape = "rectangle", fillColor = { default={ 0.4,0.8,0.125,1 }, over={ 0.66,0.15,0.15,1 } }, labelColor = { default={ 1,1,1,1 }, over={ 1,1,1,1 } }, onRelease = buttonHandler }) mainGroup:insert( recordButton ) recordButton = widget.newButton( { id = "recordButton", label = "record1", x = display.contentCenterX - 80, y = display.contentHeight - 250, width = 70, height = 32, font = appFont, fontSize = 16, shape = "rectangle", fillColor = { default={ 0.55,0.8,0.125,1 }, over={ 0.66,0.15,0.15,1 } }, labelColor = { default={ 1,1,1,1 }, over={ 1,1,1,1 } }, onRelease = buttonHandler }) mainGroup:insert( recordButton )

You have done a little mistake, you change the label of record1button but it didn’t exist you create two button recordbutton (that’s mean one is display but you can’t access to it because when you look a this value it’s contain the second button).

Try this(I can’t try the code)

-- Button handler function local buttonHandler = function( event ) if ( event.target.id == "pauseResume" ) then if ( runMode == "running" ) then runMode = "paused" pauseResumeButton:setLabel( "Resume" ) pausedAt = event.time timer.pause( timerID ) elseif( runMode == "paused" ) then runMode = "running" pauseResumeButton:setLabel( "Pause" ) timer.resume( timerID ) elseif( runMode == "stopped" ) then runMode = "running" pauseResumeButton:setLabel( "Pause" ) timerText.text = "0.000" timerID = timer.performWithDelay( timeDelay, timerText, timerIterations ) startTime = 0 pausedAt = 0 end elseif ( event.target.id == "cancel" ) then runMode = "stopped" pauseResumeButton:setLabel( "Start" ) timerText.text = "0.000" if ( timerID ) then timer.cancel( timerID ) timerID = nil end startTime = 0 pausedAt = 0 end -------------record button function----------- if ( event.target.id == "record" ) then if ( runMode == "record" ) then Record1Button:setlabel(event.time) -- it's a widget and to edit the text you to use this line timerText = event.time --Record1Button.text = recordtime --recordtime = event.time timer.record( timerID ) timerID = event.time end end end -- Create buttons pauseResumeButton = widget.newButton( { id = "pauseResume", label = "Start", x = display.contentCenterX, y = display.contentHeight - 100, width = 160, height = 32, font = appFont, fontSize = 16, shape = "rectangle", fillColor = { default={ 0.9,0.37,0.05,1 }, over={ 0.945,0.386,0.053,1 } }, labelColor = { default={ 1,1,1,1 }, over={ 1,1,1,1 } }, onRelease = buttonHandler }) mainGroup:insert( pauseResumeButton ) cancelButton = widget.newButton( { id = "cancel", label = "Cancel", x = display.contentCenterX, y = display.contentHeight - 50, width = 160, height = 32, font = appFont, fontSize = 16, shape = "rectangle", fillColor = { default={ 0.55,0.125,0.125,1 }, over={ 0.66,0.15,0.15,1 } }, labelColor = { default={ 1,1,1,1 }, over={ 1,1,1,1 } }, onRelease = buttonHandler }) mainGroup:insert( cancelButton ) recordButton = widget.newButton( { id = "recordButton", label = "Record", x = display.contentCenterX , y = display.contentHeight - 150, width = 160, height = 32, font = appFont, fontSize = 16, shape = "rectangle", fillColor = { default={ 0.4,0.8,0.125,1 }, over={ 0.66,0.15,0.15,1 } }, labelColor = { default={ 1,1,1,1 }, over={ 1,1,1,1 } }, onRelease = buttonHandler }) mainGroup:insert( recordButton ) record1Button = widget.newButton(-- you had to object with the same name. You have forgotten the 1 in record1Button { id = "recordButton", label = "record1", x = display.contentCenterX - 80, y = display.contentHeight - 250, width = 70, height = 32, font = appFont, fontSize = 16, shape = "rectangle", fillColor = { default={ 0.55,0.8,0.125,1 }, over={ 0.66,0.15,0.15,1 } }, labelColor = { default={ 1,1,1,1 }, over={ 1,1,1,1 } }, onRelease = buttonHandler }) mainGroup:insert( recordButton )

sorry, i try to fix codes. but not success.

the detail codes in below. thanks for your help.

---------------------- -- BEGIN SAMPLE CODE ---------------------- -- Require libraries/plugins local widget = require( "widget" ) -- Set app font local appFont = sampleUI.appFont -- Set local variables local timeDelay = 5 -- 1/10th of a second ( 1000 milliseconds / 10 = 100 ) local timerIterations = 60000 -- Set the timer limit to 60 seconds ( 600 \* 0.1 = 60 ) local runMode = "stopped" local startTime = 0 local pausedAt = 0 -- Forward references local timerText, pauseResumeButton, cancelButton, recordButton, timerID, recordText -- Called when the app's view has been resized (orientation changed) local function onResize( event ) pauseResumeButton.x = display.contentCenterX pauseResumeButton.y = display.contentHeight - 100 cancelButton.x = display.contentCenterX cancelButton.y = display.contentHeight - 50 timerText.x = display.contentCenterX - 15 end Runtime:addEventListener( "resize", onResize ) -- Button handler function local buttonHandler = function( event ) if ( event.target.id == "pauseResume" ) then if ( runMode == "running" ) then runMode = "paused" pauseResumeButton:setLabel( "Resume" ) pausedAt = event.time timer.pause( timerID ) elseif( runMode == "paused" ) then runMode = "running" pauseResumeButton:setLabel( "Pause" ) timer.resume( timerID ) elseif( runMode == "stopped" ) then runMode = "running" pauseResumeButton:setLabel( "Pause" ) timerText.text = "0.000" timerID = timer.performWithDelay( timeDelay, timerText, timerIterations ) startTime = 0 pausedAt = 0 end elseif ( event.target.id == "cancel" ) then runMode = "stopped" pauseResumeButton:setLabel( "Start" ) timerText.text = "0.000" if ( timerID ) then timer.cancel( timerID ) timerID = nil end startTime = 0 pausedAt = 0 end ------------------------------------------------------------------------------- -- record button function -------------------------------------------------------------------------------- if ( event.target.id == "record" ) then if ( runMode == "record" ) then Record1Button:setlabel(event.time) -- it's a widget and to edit the text you to use this line timerText = event.time --Record1Button.text = recordtime --recordtime = event.time timer.record( timerID ) timerID = event.time end end end -- Create buttons pauseResumeButton = widget.newButton( { id = "pauseResume", label = "Start", x = display.contentCenterX, y = display.contentHeight - 100, width = 160, height = 32, font = appFont, fontSize = 16, shape = "rectangle", fillColor = { default={ 0.9,0.37,0.05,1 }, over={ 0.945,0.386,0.053,1 } }, labelColor = { default={ 1,1,1,1 }, over={ 1,1,1,1 } }, onRelease = buttonHandler }) mainGroup:insert( pauseResumeButton ) cancelButton = widget.newButton( { id = "cancel", label = "Cancel", x = display.contentCenterX, y = display.contentHeight - 50, width = 160, height = 32, font = appFont, fontSize = 16, shape = "rectangle", fillColor = { default={ 0.55,0.125,0.125,1 }, over={ 0.66,0.15,0.15,1 } }, labelColor = { default={ 1,1,1,1 }, over={ 1,1,1,1 } }, onRelease = buttonHandler }) mainGroup:insert( cancelButton ) recordButton = widget.newButton( { id = "recordButton", label = "Record", x = display.contentCenterX , y = display.contentHeight - 150, width = 160, height = 32, font = appFont, fontSize = 16, shape = "rectangle", fillColor = { default={ 0.4,0.8,0.125,1 }, over={ 0.66,0.15,0.15,1 } }, labelColor = { default={ 1,1,1,1 }, over={ 1,1,1,1 } }, onRelease = buttonHandler }) mainGroup:insert( recordButton ) record1Button = widget.newButton( { id = "recordButton", label = "record1", x = display.contentCenterX - 80, y = display.contentHeight - 250, width = 70, height = 32, font = appFont, fontSize = 16, shape = "rectangle", fillColor = { default={ 0.55,0.8,0.125,1 }, over={ 0.66,0.15,0.15,1 } }, labelColor = { default={ 1,1,1,1 }, over={ 1,1,1,1 } }, onRelease = buttonHandler }) mainGroup:insert( recordButton ) record2Button = widget.newButton( { id = "recordButton", label = "record2", x = display.contentCenterX , y = display.contentHeight - 250, width = 70, height = 32, font = appFont, fontSize = 16, shape = "rectangle", fillColor = { default={ 0.55,0.8,0.125,1 }, over={ 0.66,1,1,1 } }, labelColor = { default={ 1,1,1,1 }, over={ 1,1,1,1 } }, onRelease = buttonHandler }) mainGroup:insert( recordButton ) record3Button = widget.newButton( { id = "recordButton", label = "record3", x = display.contentCenterX +80 , y = display.contentHeight - 250, width = 70, height = 32, font = appFont, fontSize = 16, shape = "rectangle", fillColor = { default={ 0.55,0.8,0.125,1 }, over={ 0.66,0.15,0.15,1 } }, labelColor = { default={ 1,1,1,1 }, over={ 1,1,1,1 } }, onRelease = buttonHandler }) mainGroup:insert( recordButton ) -- In order for the right-aligned timer to display nicely, we need a font that has monospaced digits -- Usually this is the system font and we can detect it by measuring the relative widths of the "1" and "2" characters local bestFontForDevice = nil local testText = display.newText( { x=-1000, y=-1000, text="1", font=native.systemFontBold, fontSize=16 } ) local width1 = testText.width testText.text = "2" local width2 = testText.width display.remove( testText ) if ( width2 \> width1 ) then -- The system font doesn't have monospaced digits, so use a font known to have them bestFontForDevice = ( system.getInfo("platform") == "win32" and "Courier New" or "Helvetica Neue" ) else -- The system font has monospaced digits bestFontForDevice = native.systemFontBold end -- Create timer text object timerText = display.newText( { parent=mainGroup, text="0.000", x=display.contentCenterX-15, y=105, width=310, font=bestFontForDevice, fontSize=60, align="right" }) timerText:setFillColor( 0,0.5,1 ) -- Timer function function timerText:timer( event ) if ( startTime == 0 ) then startTime = event.time end if ( pausedAt \> 0 ) then startTime = startTime + ( event.time - pausedAt ) recordtime = startTime + ( event.time - pausedAt ) pausedAt = 0 end self.text = string.format( "%.3f", (event.time - startTime)/1000 ) if ( ( event.time - startTime ) \>= ( timerIterations \* timeDelay ) ) then print( "Resetting timer..." ) buttonHandler( { target={ id="cancel" } } ) end end