Killing an Object Help

When my game starts, I create an object that listens for a touch event. When that event fires, I pass that object that was passed in to the event listener to a function that does a removeSelf().

function myObject:touch(e)
if (e.phase == “ended”) then
killMe(self)

This works great unless the game ends because the timer ran out. Since there is no myObject available when the timer runs out, I can’t call the killMe(self) function.

There is only one myObject at any given time. Should I create a global variable and assign it to myObject so that I can kill that global variable when the timer runs out? What would be the best way to handle this? [import]uid: 41809 topic_id: 16981 reply_id: 316981[/import]

try this

[lua]function killMe(self)
if not self then return end
if self.removeSelf then
self:removeSelf()
self=nil
end
end
[import]uid: 7177 topic_id: 16981 reply_id: 63700[/import]

How do I ensure that the final object gets killed? Since there is no event that triggers the end of the game, I don’t have an object to send to the killMe function.

[import]uid: 41809 topic_id: 16981 reply_id: 63823[/import]