Corona timer.performWithDelay bug

Hello,

If you call the timer.performWithDelay function within a loop then the function will be called instantly no matter what time you specify.

bug demo…

local function removeTornado(obj) print("removing tornado...") Runtime:removeEventListener("enterFrame", obj ) display.remove(obj) obj = nil end for i = 1, 2 do local tornado = display.newCircle(100\*i,100,20) tornado.name = i function tornado:enterFrame(event) print(tornado.name) end Runtime:addEventListener("enterFrame", tornado) timer.performWithDelay( 10000, removeTornado(tornado), 1 ) end

You can’t call it the way you’re calling it.

First, your for loop will start two timers that fire off in 10 seconds.  They however won’t fire off one at 10 seconds and one at 20 seconds, they both fire at 10 seconds.

When you call:  timer.performWithDelay( 10000, removeTornado(tornado**)**, 1 )

removeTornado(tornado) runs immedietly.  If that function were to return a function, then in 10 seconds that returned function would run, but as it is your function returns nothing, so in 10 seconds, nothing is run.

Since you seem to need to pass the object, you want to use a closure to do this:

timer.performWithDelay( 10000, function() removeTornado** (tornado); end,** 1 )

Hope this helps.  Rob

You can’t call it the way you’re calling it.

First, your for loop will start two timers that fire off in 10 seconds.  They however won’t fire off one at 10 seconds and one at 20 seconds, they both fire at 10 seconds.

When you call:  timer.performWithDelay( 10000, removeTornado(tornado**)**, 1 )

removeTornado(tornado) runs immedietly.  If that function were to return a function, then in 10 seconds that returned function would run, but as it is your function returns nothing, so in 10 seconds, nothing is run.

Since you seem to need to pass the object, you want to use a closure to do this:

timer.performWithDelay( 10000, function() removeTornado** (tornado); end,** 1 )

Hope this helps.  Rob