Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Change timer delay via ._delay smt dosn't work
Started by stalxerhd Dec 01 2019 09:32 PM

- - - - -
2 replies to this topic

Best Answer XeduR @Spyric , 02 December 2019 - 08:29 AM

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

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

stalxerhd

[GLOBAL: userInfoPane.html]
stalxerhd
  • Observer

  • 23 posts
  • Corona SDK

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


[TOPIC: post.html]
#2

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Corona Geek

  • 1,103 posts
  • Corona SDK

  Best Answer

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

  • stalxerhd likes this

[TOPIC: post.html]
#3

stalxerhd

[GLOBAL: userInfoPane.html]
stalxerhd
  • Observer

  • 23 posts
  • Corona SDK

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




[topic_controls]
[/topic_controls]