Perform first, then delay

I don’t agree w/ the assessment that it would be better that way, but…

Corona is an SDK (software development kit) and Lua is easy to use, so nothing is stopping you implementing your own timer.performWithDelay

function timer.performWithDelay2( ... ) for i = 1, #arg, 2 do timer.performWithDelay( arg[i+1], arg[i] ) end end local function func1() print("You can solve") end local function func2() print("These problems") end local function func3() print("On your own through coding.") end local function func4() print("That is the beauty of an SDK.") end timer.performWithDelay2( func1, 500, func2, 1000, func3, 1500, func4, 2000 )

Is this function some sort of extension to the timer library? 

Maybe because I’m used to it this way coming from SpriteKit. In SpriteKit there is that thing called “Actions” they are the equivalent of transitions in corona, but they have more functions than (move, scale, rotate) there is something called:

-“skAction.waitForDuration” 

-“skAction.runBlock” <-- run block of code.

You can create a sequence of actions and then run them on any object you want or the scene itself:

skAction.sequence([function, wait, function, wait, function, wait]) scene.runAction(sequence)

To me, it’s easier that way for something like spawn different kinds of enemies at different times, but if there is a more efficient way to achieve that, please suggest it to me.

That is a function I just wrote to do it the way you wanted to do timers.

Well, the way SpriteKit does it is neither here or there.  performWithDelay is unlikely to ever change as that would break all kinds of old code.

As I suggested, if you need helpers or extensions to existing libraries, simply add them.  That is a benefit of working with Lua.  It is SUPER easy to extend existing libraries and modules.

I get that, I was asking if this is how you make an extension in Lua, because I googled “Lua library extensions” and couldn’t find anything useful. 

Ah, I see. 

Yes, this is a way to extend the functionality of a library/module.

Lua is very friendly that way.  You can attach new functions and fields to any table and a module/library is nothing more than a table with fields and functions attached to it.

Wonderful, thanks a lot. 

I’m trying to cancel a timer but it doesn’t get canceled when it should:

local fireTimer local function onTouch( self, event ) if( event.phase == "began") then fireTimer =&nbsp;timer.performWithDelay( 3000, fire, 0&nbsp;)&nbsp;\<-- works fine elseif( event.phase == "ended" ) then timer.cancel( fireTimer ) \<-- doesn't work, it keeps going, "pause" doesn't work either end end

Can you put a print statement inside the elseif clause to make sure you’re getting to that part of the code?

the “ended” phase does get executed, it’s the first thing I checked.