how to return a value from a function

hi,

i do little function to move my character in function of the tap.

the problem is how to assign the event.x or event.y in the function “myTapListener” to the “animationPersonnage”  ? it seems that the event.x value is egal to nil

animationPersonnage.x=148 animationPersonnage.y=152 local function myTapListener(event)   transition.from( animationPersonnage, { tag="animationPersonnagedeplacement", time=1000, x=event.x, y=event.y } )   local nouvellecoordonneex = event.x   local nouvellecoordonneey = event.y   print("object tapped = "..tostring(event.target))   return true end water1:addEventListener("tap", myTapListener ) animationPersonnage.x=event.x animationPersonnage.y=event.y

event.x and event.y are local to myTapListener function.

You need to add below 2 statements inside myTapListener  function so that event.x and event.y will be with in scope.

animationPersonnage.x=event.x animationPersonnage.y=event.y

On the other hand , if you want to use them outside the function , you need to return those values and catch them back and use those after the function call.

-J

https://www.facebook.com/NookQuickTipsAndUpdates

I have already put this value inside my function but they are not considered.

it doesn’t work

local function deplacementPersonnage ()   transition.to( animationPersonnage, { tag="deplacementPersonnage", time=100, x=event.x, y=event.y } )   animation.x=event.x   animation.y=event.y end --INTERACTIVITE TAP local function myTapListener(event)   transition.from( animationPersonnage, { tag="animationPersonnagedeplacement", time=1000, x=event.x, y=event.y } )   transition.scaleBy( animationPersonnage, {time=600, xScale=animationPersonnage.xScale\*-2,   yScale=animationPersonnage.yScale\*-2 })   transition.to (animationPersonnage, {rotation=180, time=30})   animationPersonnage.x=event.x   animationPersonnage.y=event.y   print("object tapped = "..tostring(event.target))   return true end water1:addEventListener("tap", myTapListener )

it’s the solution

local function deplacementPersonnage ()   transition.to( animationPersonnage, { tag="deplacementPersonnage", time=100, x=event.x, y=event.y } )   animation.x=event.x   animation.y=event.y end --INTERACTIVITE TAP local function myTapListener(event)   transition.from( animationPersonnage, { tag="animationPersonnagedeplacement", time=1000, x=event.x, y=event.y } )   transition.scaleBy( animationPersonnage, {time=600, xScale=animationPersonnage.xScale\*-2,   yScale=animationPersonnage.yScale\*-2 })   transition.to (animationPersonnage, {rotation=180, time=30})   return true, event.x, event.y end background:addEventListener("tap", myTapListener )

event.x and event.y are local to myTapListener function.

You need to add below 2 statements inside myTapListener  function so that event.x and event.y will be with in scope.

animationPersonnage.x=event.x animationPersonnage.y=event.y

On the other hand , if you want to use them outside the function , you need to return those values and catch them back and use those after the function call.

-J

https://www.facebook.com/NookQuickTipsAndUpdates

I have already put this value inside my function but they are not considered.

it doesn’t work

local function deplacementPersonnage ()   transition.to( animationPersonnage, { tag="deplacementPersonnage", time=100, x=event.x, y=event.y } )   animation.x=event.x   animation.y=event.y end --INTERACTIVITE TAP local function myTapListener(event)   transition.from( animationPersonnage, { tag="animationPersonnagedeplacement", time=1000, x=event.x, y=event.y } )   transition.scaleBy( animationPersonnage, {time=600, xScale=animationPersonnage.xScale\*-2,   yScale=animationPersonnage.yScale\*-2 })   transition.to (animationPersonnage, {rotation=180, time=30})   animationPersonnage.x=event.x   animationPersonnage.y=event.y   print("object tapped = "..tostring(event.target))   return true end water1:addEventListener("tap", myTapListener )

it’s the solution

local function deplacementPersonnage ()   transition.to( animationPersonnage, { tag="deplacementPersonnage", time=100, x=event.x, y=event.y } )   animation.x=event.x   animation.y=event.y end --INTERACTIVITE TAP local function myTapListener(event)   transition.from( animationPersonnage, { tag="animationPersonnagedeplacement", time=1000, x=event.x, y=event.y } )   transition.scaleBy( animationPersonnage, {time=600, xScale=animationPersonnage.xScale\*-2,   yScale=animationPersonnage.yScale\*-2 })   transition.to (animationPersonnage, {rotation=180, time=30})   return true, event.x, event.y end background:addEventListener("tap", myTapListener )