Is there any way to change the rate at which timer.performWithDelay() functions?

Basically I have a function that generates objects on the screen, I used timer.performWithDelay() to generate those objects at a set rate of time. I would prefer that these objects spawn at a rate that increases as the game goes on, so I was wondering if it were possible to change the rate at which the timer.performWithDelay() functions (like instead of being a set number of milliseconds, that number goes down every x number of milliseconds). The more obvious way would be to go ahead and create a function that manages that, but I’m having trouble actually making that. Please have a look at the code below:

local function generateRandomThings() local orange = display.newImageRect( mainGroup, "orange.png", 40, 40) orange.myName = "orange" table.insert(ballsTable,orange) physics.addBody(orange, {radius=20}) orange.x = math.random(display.screenOriginX + 20, \_W - 20) orange.y = -100 end

The above code generates the object at random places on the screen.

ballGenTimer = timer.performWithDelay(50,generateRandomThings,0)

This timer (local “ballGenTimer” is declared at the very top of my game.lua) is in my scene:show. 

Thanks in advance!

There’s a few ways. You can either cancel the timer and start a new one each time the delay rate changes. Or you set up your own timer system, where you manually track the time elapsed since the event last triggered in an enterFrame listener, and if it is >= the current rate, fire the event and set the comparison variable to system.getTimer().

Everything nick said is right.  You can also change your code to use a new duration on each call like this:

local timerPeriod = 50 local function generateRandomThings() local orange = display.newImageRect( mainGroup, "orange.png", 40, 40) orange.myName = "orange" table.insert(ballsTable,orange) physics.addBody(orange, {radius=20}) orange.x = math.random(display.screenOriginX + 20, \_W - 20) orange.y = -100 -- change period anywhere or here if you like ballGenTimer = timer.performWithDelay( timerPeriod ,generateRandomThings ) end ballGenTimer = timer.performWithDelay( timerPeriod,generateRandomThings)

i.e. Don’t use an infinite timer

Yep got things exactly the way I wanted them to, thank you both so much! 

There’s a few ways. You can either cancel the timer and start a new one each time the delay rate changes. Or you set up your own timer system, where you manually track the time elapsed since the event last triggered in an enterFrame listener, and if it is >= the current rate, fire the event and set the comparison variable to system.getTimer().

Everything nick said is right.  You can also change your code to use a new duration on each call like this:

local timerPeriod = 50 local function generateRandomThings() local orange = display.newImageRect( mainGroup, "orange.png", 40, 40) orange.myName = "orange" table.insert(ballsTable,orange) physics.addBody(orange, {radius=20}) orange.x = math.random(display.screenOriginX + 20, \_W - 20) orange.y = -100 -- change period anywhere or here if you like ballGenTimer = timer.performWithDelay( timerPeriod ,generateRandomThings ) end ballGenTimer = timer.performWithDelay( timerPeriod,generateRandomThings)

i.e. Don’t use an infinite timer

Yep got things exactly the way I wanted them to, thank you both so much!