Change timer delay via ._delay smt dosn't work

I have a code wich display object (crosshair) at the point where the user taps.

  • If crosshair doesn’t exist, It creates it and starts the countdown (1 sec) to remove
  • If crosshair already exist, It changes coordinates and set timer ._delay countdown back to 1 sec

I tested this code and see, that ._delay reset sometimes doesn’t just work - coordinates changed but crosshair exist less than 1 sec.

Did I smth wrong?

local tapAreaFlag=false local tapArea local tapAreaTimer local function tap ( event )     local CoordXtap, CoordYtap = event.x, event.y     if tapAreaFlag== false then         tapArea= display.newCircle( mainGroup, CoordXtap,CoordYtap, 50)         tapArea.fill = { type = "image", sheet = uiFrames, frame = 8 }          tapAreaTimer=timer.performWithDelay (1000, function () tapAreaFlag = false display.remove( tapArea )  end )         tapAreaFlag = true     elseif tapAreaFlag == true then         tapArea.x, tapArea.y = CoordXtap, CoordYtap         tapAreaTimer.\_delay=1000     end end

You are just updating a table entry.

The simplest and easiest approach would just be to check if the timer exists, and if it does, then just cancel it, i.e.

-- start of the function if yourTimer then timer.cancel( yourTimer ) end -- rest of the function

XeduR @Spyric thank you for advice, cancel previous if exist and start new - works all the time