Can't Add a Runtime Listener?

Hi All,

I’m trying to add a Runtime listener to implement a swipe function to show an options menu. However Everytime I add the listener the simulator crashes with an “Assertion Error” error.

this is the code i’m adding:

Runtime:addEventListener( "touch", onScreenTouch ) local function onSceneTouch( self, event ) if event.phase == "ended" then if event.xStart \< event.x and (event.x - event.xStart) \>= 30 then transition.to ( optionsGroup, { time = 500, x=75 } ) transition.to ( optionsGroup, { time = 500, alpha = 1, delay = 200} ) transition.to ( optionsButt, {time = 500, x=(backEdgeX + 250)} ) return true end end end

Any ideas why I suddenly can’t add this listener?

You can’t add it until it exists.  Move the addEventListener below the function definition.

Hi Rob,

Thanks for the reply. I have the function defined near the top of my code right before the CreatScene. I have put the Runtime:addEventListener near the bottom with all the scene listeners for storyboard.

I still get the error Assertion Failed.

And take the “self” out of the parameters.

I would also put the listener for this in your enterScene() function and then remove it in exitScene()

Thanks

Rob

Hi Rob,

I have tried putting it in the enter scene, and almost everywhere else possible. And I still get the same error. I did remove the “self” though.

Found the problem. I had onScreenTouch in the listener declaration, and onSceneTouch in the actual function… so just a typo. The joys of programming.

Sorry for the waste of time lol.

You can’t add it until it exists.  Move the addEventListener below the function definition.

Hi Rob,

Thanks for the reply. I have the function defined near the top of my code right before the CreatScene. I have put the Runtime:addEventListener near the bottom with all the scene listeners for storyboard.

I still get the error Assertion Failed.

And take the “self” out of the parameters.

I would also put the listener for this in your enterScene() function and then remove it in exitScene()

Thanks

Rob

Hi Rob,

I have tried putting it in the enter scene, and almost everywhere else possible. And I still get the same error. I did remove the “self” though.

Found the problem. I had onScreenTouch in the listener declaration, and onSceneTouch in the actual function… so just a typo. The joys of programming.

Sorry for the waste of time lol.