function on_message(self, message_id, message, sender)
-- if collide
-- then play particle effects
-- delete game object
-- wait 1.5 seconds
-- game over
if message_id == hash("collision_response") then
particlefx.play("#player_particle")
go.delete()
self.timeout = timer.delay(1.5, false, function()
msg.post("controller:/controller", "game_over")
end)
end
end
Just guessing here, but since you delete the current game object, and it’s script, both the timer (which belongs to the script) and the callback are also deleted.
If you instead put the go.delete() is inside the callback function, it should work.
function final(self)
msg.post(".", "release_input_focus")
msg.post("controller:/controller", "game_over")
end
function on_message(self, message_id, message, sender)
if message_id == hash("collision_response") then
particlefx.play("#player_particle")
msg.post(".", "disable")
self.timeout = timer.delay(1, false, function()
go.delete()
end)
end
end
Is it fine to post msg.post("controller:/controller", "game_over")at the final function?
If I place it to:
function on_message(self, message_id, message, sender)
if message_id == hash("collision_response") then
particlefx.play("#player_particle")
msg.post(".", "disable")
self.timeout = timer.delay(1, false, function()
go.delete()
msg.post("controller:/controller", "game_over")
end)
end
end
It works, but I have errors in console:
ERROR:GAMESYS: The collection /main/game/game_over.collectionc could not be loaded since it was already. Message 'load' sent from controller:/controller#script to controller:/controller#game_over_proxy.
ERROR:GAMESYS: The collection /main/game/game.collectionc could not be unloaded since it was never loaded. Message 'unload' sent from controller:/controller#script to controller:/controller#game_proxy.
DEBUG:SCRIPT: proxy_loaded url: [controller:/controller#game_over_proxy]
DEBUG:SCRIPT: proxy_unloaded url: [controller:/controller#game_proxy]
I’m curious about the second case though, since by the loks of the console output, it seems the message gets sent twice?
What if you put a print next to the delete, do you get one or two printouts?
I forgot that I have to use “trigger_response” instead “collision_response”. Now it’s all right.
function on_message(self, message_id, message, sender)
if message_id == hash("trigger_response") and message.enter then
particlefx.play("#player_particle")
msg.post(".", "disable")
self.timeout = timer.delay(1, false, function()
go.delete()
msg.post("controller:/controller", "game_over")
end)
end
end