How to change delay time on timer during run time.

Hi, I am a newbie and this is my first time here so please go easy on me,lol.
On to my question. I have a timer that calls a function that throws balloons every 3 seconds forever,how do I shorten the delay time so the balloons are thrown faster?
I tried replacing the delay time with a variable so i can change it if conditions are met in the balloon throwing function, but i does not work.
I know the value changes as I want it because I output it. But the timer ignores it. Can the timer parameters be defined only before run time?

Example:

local count = 0
local delayTime = 3000

local function balloonFunction()

if(count > 5)then
delayTime = 2000
end

throwBallon()
count = count + 1

end

local throwBalloonLoop = timer.performWithDelay(delayTime, balloonFunction, 0)

You have to cancel the timer, and then restart it with the new value. In order to do that you need to save the reference to the timer, in a scope where it can be seen by the function that needs to amend it.

[lua]

local myTimer =timer.performWithDelay(myDelay, myFunction)

– later on…

timer.cancel(myTimer)

myTimer = nil

myTimer =timer.performWithDelay(myDelay, myFunction)

[/lua]

How I usually do it is to roll my own timer.

[lua]

local myDelay = 3000

local time = system.getTimer()

local myTimedFunction ()

 – do my timed stuff here

end

local gameLoop = function ()

 local t = system.getTimer()

if t - time >= myDelay then

  myTimedFunction()

  time = system.getTimer()

  myDelay = myDelay - 100

end

end

Runtime:addEventListener(“enterFrame”, gameLoop)

[/lua]

Thanks, that was quick. I will try this immediately.

Thanks a million, it works!!!

Hello,

Just change the event._delay parameter on the function.

Sincerely,
Yvan.

You have to cancel the timer, and then restart it with the new value. In order to do that you need to save the reference to the timer, in a scope where it can be seen by the function that needs to amend it.

[lua]

local myTimer =timer.performWithDelay(myDelay, myFunction)

– later on…

timer.cancel(myTimer)

myTimer = nil

myTimer =timer.performWithDelay(myDelay, myFunction)

[/lua]

How I usually do it is to roll my own timer.

[lua]

local myDelay = 3000

local time = system.getTimer()

local myTimedFunction ()

 – do my timed stuff here

end

local gameLoop = function ()

 local t = system.getTimer()

if t - time >= myDelay then

  myTimedFunction()

  time = system.getTimer()

  myDelay = myDelay - 100

end

end

Runtime:addEventListener(“enterFrame”, gameLoop)

[/lua]

Thanks, that was quick. I will try this immediately.

Thanks a million, it works!!!

Hello,

Just change the event._delay parameter on the function.

Sincerely,
Yvan.