How to check if 2 seconds has passed

Hey guys!
 

Quick question again…

function countTime( event ) -- Count Time Function Used By The Button if clicked == 0 then timeStart = os.time() print("Starting Time: " .. timeStart) button1.x = 500 button2.x = display.contentCenterX clicked = 1

When I click a button, it sets time start to os.time()

How do I constantly check my program to see if two seconds has passed so I can do something from there?

Thanks!

I wouldn’t approach it that way.  I’d  simply use performWithDelay and a count of 2000 milliseconds.

-- This code demonstrates the premise of how I'd achieve a 2 second delay local button = display.newRect( 100, 100, 100, 30 ) local actionIndicator = display.newCircle( 200, 200, 30 ) local function doAction() actionIndicator:setFillColor(0,1,0) end function button.touch( self, event ) if( event.phase ~= "ended" ) then return true end timer.performWithDelay( 2000, doAction ) self:removeEventListener("touch") return true end button:addEventListener( "touch" )

I wouldn’t approach it that way.  I’d  simply use performWithDelay and a count of 2000 milliseconds.

-- This code demonstrates the premise of how I'd achieve a 2 second delay local button = display.newRect( 100, 100, 100, 30 ) local actionIndicator = display.newCircle( 200, 200, 30 ) local function doAction() actionIndicator:setFillColor(0,1,0) end function button.touch( self, event ) if( event.phase ~= "ended" ) then return true end timer.performWithDelay( 2000, doAction ) self:removeEventListener("touch") return true end button:addEventListener( "touch" )