I’m developing my first game with Corona SDK. I have grenades that I want to explode either when they hit an enemy or otherwise after 3 seconds. I’m having trouble with the timer situation.
In my createGrenade function, I use a timer.performWithDelay to call a selfDestruct function. I use a closure for this:
local myclosure = function() return selfDestruct(grenade) end timer.performWithDelay(3000, myclosure)
In the selfDestruct function I want to check that the grenade still
exists (I don’t want to blow up a grenade that has already exploded). I start with:
local function selfDestruct(grenade) if grenade then display.remove(grenade) explosionChannel = audio.play(explosionSound)
But even if the grenade has already been removed after hitting an enemy, I’m still hearing the explosion sound after 3 seconds. I’m new to Lua and Corona SDK. Could anybody give me a hint as to where I’m going wrong?
Thanks