I would actually recommend NOT using anonymous functions (or closures) in that way for that very reason.
WhiteTree Games - Home, home on the web, where the bits and bytes they do play! #MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
local listener =function(event)print("active my event")end
mySprite:addEventListener("onMyEvent", listener)
mySprite:removeEventListener("onMyEvent", listener)
You only need to be aware of scopes, if you remove listener in other scope, then you either make listener as property of bigger scope (as class, for example), or make it global.
Well I could be wrong, but I do this.... local timer = Timer.new(5000, 1) timer:addEventListener(Event.TIMER, function(event) --[[Do my shit here in 5 seconds]] end ) timer:start()
REAL programmers type copy con filename.exe ---------------------------------------
Comments
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
Likes: saeys
local timer = Timer.new(5000, 1)
timer:addEventListener(Event.TIMER,
function(event)
--[[Do my shit here in 5 seconds]]
end
)
timer:start()
---------------------------------------
Likes: Cyberience