I am attempting to remove a runtime event listener within the listener function, but it is not working.
Here is my code:
local onFrame = function(event) print("You Win!") Runtime:removeEventListener("enterFrame", onFrame) end function scene:create( event ) local sceneGroup = self.view params = event.params background = display.newRect(0,0, display.contentWidth, display.contentHeight) background.anchorX = 0 background.anchorY = 0 background:setFillColor( 0, 0, 0 ) sceneGroup:insert(background) Runtime:addEventListener("enterFrame", onFrame) end
What I am expecting it to do is create the runtime listener, enter it once, print “You Win!” to the console, then remove the listener. What it is doing is calling the function repeatedly, printing “You Win!” until I kill the program.
What am I missing here?