We're going to execute the timer for the eggs, so that they can start dropping on the screen. To make the egg drop, perform the following steps:
Create a local function called
eggTimer()
and usetimer.performWithDelay
to drop an egg every 1 second (1000
milliseconds) repeatedly. UseeggDrop()
to activate the drop:local eggTimer = function() startDrop = timer.performWithDelay( 1000, eggDrop, 0 ) end
Within the first
if
statement in theonEggCollision()
function, cancel the timer using thetimerID
andstartDrop
variables. Add theif
gameLives < 1
statement then to stop the eggs from falling:if gameLives < 1 then timer.cancel( startDrop ) print("timer cancelled") end