Need help in improving this code.....

I have a code where I detect clockwise,anticlockwise swipes in left side of the screen and just a touch on right side of screen.The problem is that when I start simulator and at the start if I touch right part of the screen it shows me this error( please see image attached.).But when I relaunch simulator and at the start & swipe clockwise or anticlockwise on left part of the screen, it does not show any error, though after that I touch right part again & again.  :huh: Why???. 

Also when I touch on right part, it prints tapON and tapREMOVED as I want.But it also prints clockwise.Can somebody help me solving this issue?

Thanks.

 local beginX local beginY local endX local endY local clockwise local anticlockwise function checkSwipeDirection() clockwise = math.abs(endX - beginX) anticlockwise = math.abs(endY - beginY) if (endX \< beginX) and ( endY \> beginY) then print("clockwise") elseif (endX \> beginX) and (endY \> beginY) then print("Anticlockwise") end end function swipe(event) if event.phase == "began" then if ( event.x \> 300) then print("tapON") elseif ( event.x \< 300) then beginX = event.x beginY = event.y end end if event.phase == "ended" then if ( event.x \> 300) then print("tapREMOVED") elseif ( event.x \< 300) then endX = event.x endY = event.y end checkSwipeDirection(); end end Runtime:addEventListener("touch", swipe)

The error is because you don’t assign endX a value before you use it in checkSwipeDirection(). You need to assign a value to it in “ended” phase in both if statements because you are calling checkSwipeDirection() either way.

I didn’t get the second problem and it doesn’t seem to be happening on simulator.

The error is because you don’t assign endX a value before you use it in checkSwipeDirection(). You need to assign a value to it in “ended” phase in both if statements because you are calling checkSwipeDirection() either way.

I didn’t get the second problem and it doesn’t seem to be happening on simulator.