Multiple Swipes Occuring

I have an issue with multiple swipes occurring. Basically, my code allows the user to swipe a spaceship and the spaceship, with a transition, will move to a designated location. But even when you swipe once, multiple swipes occur (the number of times is random), and the other parts of the function besides the transition are called multiple times. 

Here is the code:

[lua]

local function moveSpaceshipOnSwipe(event)

local swipeLength = math.abs(event.x - event.xStart)

print(event.phase, swipeLength)

if (bluespaceship.swipable == “yes”) then

if (event.phase == “began”) then

—Do nothing

end

if (event.phase == “moved”) then

if (event.xStart > event.x and swipeLength > 30) then

print(“Swiped Left”)

end

if (event.xStart < event.x and swipeLength > 30) then

bluespaceship:setLinearVelocity(0,0)

bluespaceship.alpha = 1

–timer.performWithDelay(800, sendToPlanet, 1)

print(“Swiped Right”)

if (rfn == 1) then

transition.to(bluespaceship, {time = 1000, x = blueplanet.x, y = blueplanet.y, onComplete = sendToPlanet} )

end

if (rfn == 3) then

transition.to(bluespaceship, {time = 1000, x = purpleplanet.x, y = purpleplanet.y, onComplete = sendToPlanet} )

end

if (rfn == 7) then

transition.to(bluespaceship, {time = 1000, x = bluegreenplanet.x, y = bluegreenplanet.y, onComplete = sendToPlanet} )

end

end

rstmr = timer.performWithDelay(1500, removeSP, 1)

end

if (event.phase == “ended”) then

–Do nothing

end

end

if (bluespaceship.swipable == “uncertain”) then

if (event.phase == “moved”) then

spaceshipLives = spaceshipLives - 1

print(spaceshipLives)

end

end

end

bluespaceship:addEventListener(“touch”, moveSpaceshipOnSwipe)

[/lua]

This is the output in the console after one swipe. 

6/12/14 11:13:34.269 PM Corona Simulator[3686]: began 0

6/12/14 11:13:34.364 PM Corona Simulator[3686]: moved 1

6/12/14 11:13:34.380 PM Corona Simulator[3686]: moved 10

6/12/14 11:13:34.403 PM Corona Simulator[3686]: moved 27

6/12/14 11:13:34.444 PM Corona Simulator[3686]: moved 65

6/12/14 11:13:34.444 PM Corona Simulator[3686]: Swiped Right

6/12/14 11:13:34.454 PM Corona Simulator[3686]: moved 77

6/12/14 11:13:34.455 PM Corona Simulator[3686]: Swiped Right

6/12/14 11:13:34.468 PM Corona Simulator[3686]: moved 92

6/12/14 11:13:34.468 PM Corona Simulator[3686]: Swiped Right

6/12/14 11:13:34.476 PM Corona Simulator[3686]: ended 92

I just don’t understand why it’s being called multiple times, and why that number is random each time. Can someone please tell me why this is occurring and a possible solution? Thanks.

A shot in the dark here as your’ve left out code that might shed more light.

based on the code you have posted - 

Move stuff out of the moved area and put that code in ended.

t.

Wow, I never realized that the reason was because the “moved” phase will result in multiple callings of the function. Thank you so much!

A shot in the dark here as your’ve left out code that might shed more light.

based on the code you have posted - 

Move stuff out of the moved area and put that code in ended.

t.

Wow, I never realized that the reason was because the “moved” phase will result in multiple callings of the function. Thank you so much!