Switching Linear Velocity

Can somebody help me correct this code so when i touch the screen to switch the linear velocity to the opposite of what it is.

charA:setLinearVelocity( 0, 250 ) local CharV = charA:getLinearVelocity() local function onObjectTouch( event ) if CharV \> -1 then charA:setLinearVelocity(0,250) else CharA:setLinearVelocity(0,-250) end end background:addEventListener( "touch", onObjectTouch )
charA:setLinearVelocity( 0, 250 ) local function onObjectTouch( event ) local vx, vy = charA:getLinearVelocity() CharA:setLinearVelocity( -vx, -vy ) end background:addEventListener( "touch", onObjectTouch )

Don’t forget about touch event phases.  “began”, “moved”, “ended”.

i just replaced touch with tap to make it simple and it works

charA:setLinearVelocity( 0, 250 ) local function onObjectTouch( event ) local vx, vy = charA:getLinearVelocity() CharA:setLinearVelocity( -vx, -vy ) end background:addEventListener( "touch", onObjectTouch )

Don’t forget about touch event phases.  “began”, “moved”, “ended”.

i just replaced touch with tap to make it simple and it works