I'm trying to start a timer when a touch event happens, then stop after a pre set amount of time. The app I'm making goes like this:
local randomButton = display.newCircle(250, 350, 80)
randomButton:setFillColor(200, 0, 0)
timesTouched = 0
timeLimit = 1
touchTimer = 0
local function touchCount()
timesTouched = timesTouched + 1
print("Touched " .. tostring(timesTouched) .. " times")
end
local function randomColor(event)
if (timesTouched < 1) then
touchTimer = timer.performWithDelay (0, touchCount, 1)
end
if (touchTimer.count == (timeLimit * 1000)) then
print("The button has been touched " .. timesTouched .. " in " .. tostring(timeLimit) ..
" seconds")
end
end
randomButton:addEventListener ( "touch", randomColor)
I didn't want to give out almost all my code, but I figure if I didn't you wouldn't know what I was talking about or trying to do. So how do I get the timer to stop after ten seconds, then print a line telling me how many times I touched the button in 10 seconds? I'd really appreciate the help. I've been looking up the API and some Tutorials but nothing touches on my exact situation.