Removing event listener on collision

Hello, I’m not sure which way is the right one so I’m gonna ask:

Is this one right?

nloDrop = function()    nlo.collision = nloCollision     nlo:addEventListener("collision", nlo) end function nloCollision(self, event)     self:removeEventListener("collision", self) -- THIS PART     self:removeSelf()     self = nil end  

Or is this one right?

nloDrop = function()    nlo.collision = nloCollision     nlo:addEventListener("collision", nlo) end function nloCollision(self, event)     self:removeEventListener("collision", nlo) -- THIS PART     self:removeSelf()     self = nil end  

I think both ways work, but I don’t know which one is better.

Thanks.

Hi @kizzwiz,

Both should be fine. I suppose I’d go with #1 because it doesn’t need to up-reference “nlo”, wherever that is declared… but in terms of performance, the difference would be imperceptible.

Brent

Thanks, Brent!

Hi @kizzwiz,

Both should be fine. I suppose I’d go with #1 because it doesn’t need to up-reference “nlo”, wherever that is declared… but in terms of performance, the difference would be imperceptible.

Brent

Thanks, Brent!

Thnx kizzwiz , for sharing this one

Thnx kizzwiz , for sharing this one