Hi - I am making a shoot 'em up and I want to call a function 2 seconds after my player is destroyed.
I found the timer.delay
method, and think I’ve added it correctly but it doesn’t seem to run the callback.
I am using the following code:
function on_message(self, message_id, message, sender)
-- Collide with enemy
if message_id == hash("collision_response") and message.other_group == hash("enemies") then
local pos = go.get_position()
factory.create( 'fx#explode', pos, nil, { type = hash( "large" ) } )
timer.delay( 2, false,
function( self, handle, time_elapsed )
msg.post( '/game', 'player-dead' )
end
)
go.delete()
end
If I run the msg.post
without the timer.delay
then it works as I expect. With the timer.delay
the code runs with no errors but nothing happens when the player is removed.
Have I missed something/ done something wrong?
Thanks!