user805687
user805687

Reputation:

How can I delay, or pause, a function in ansca's corona? (lua)

I can't find it documented anywhere :/

(question is the title)

found this but can't get it to work.

function onCollision( event )
   --code-- 
end

Runtime:addEventListener( "collision", listener )

 local function listener( event )
     timer.performWithDelay(
1000, onCollision )
end

Upvotes: 3

Views: 2428

Answers (1)

Conspicuous Compiler
Conspicuous Compiler

Reputation: 6469

Your issue is one of code order. function essentially sets the value for the given symbol. From the Lua manual:

The statement

 function f () body end

translates to

 f = function () body end

As such, listener is nil at the time you're passing it to addEventListener. Reorder, and it should work:

function onCollision( event )
   --code-- 
end

local function listener( event )
  timer.performWithDelay(1000, onCollision )
end

Runtime:addEventListener( "collision", listener )

Upvotes: 2

Related Questions