variable changing in a timer // timer.performWithDelay (delay variable , function , loop)

I want to change the delay variable in the timer when some condition happens. I declare some variable at first like

timechange = 200 and after some condition I made timechange= timechange + 100

timer.performWithDelay (timechange , function_something , -1)

but program does not responses any delay change.

Thank you in advance for your help [import]uid: 74718 topic_id: 12400 reply_id: 312400[/import]

It’s because the timer is still running on the time it was originally set it, cancel and restart it.

If you need to calculate remaining time or resume from where it was left off, there is a thread somewhere (use search) about doing so :slight_smile: [import]uid: 52491 topic_id: 12400 reply_id: 45197[/import]

you can do it like this

[lua] local timechange = 200
timeTaken = timer.performWithDelay( timechange, tickerFunction, 10000 )

–to reset the timer
timechange = timechange + 100
timer.cancel(timeHandle)
timeHandle = timer.performWithDelay( timechange, tickerFunction, 10000 ) [/lua]

if you want to keep track of the number of time the timer is ticked you can declare the value in a variable and can decrement it on each tick…and start from there when u reset the timer
like this

[lua] local totalSteps = 10000
local ticked = 0

local function tickerFunction()
– timer tick function
ticked = ticked + 1
end

local timechange = 200
timeTaken = timer.performWithDelay( timechange, tickerFunction, totalSteps )

–to reset the timer
timechange = timechange + 100
timer.cancel(timeHandle)
timeHandle = timer.performWithDelay( timechange, tickerFunction, totalSteps - ticked ) [/lua] [import]uid: 71210 topic_id: 12400 reply_id: 45356[/import]

thank you all it solved my problem [import]uid: 74718 topic_id: 12400 reply_id: 45505[/import]