Passing variables/ params to a function within another function -- please help!

I search the forum and found several example of how to pass variable/param to a function, however, none of them work for my situation. What I want to do is to pass, a variable to each one of these functions. Please see below. Iam trying pass a value for a, b, c, d, e, f which will then change the x and y value for each functions.

local function ballAni(a)  
  
  
  
 local animUp4 = function(b)  
  
 ballTween = transition.to(frog, { time=2000, x=b, onComplete=hidepath})  
  
 end  
  
 local animUp3 = function(c)   
  
 ballTween = transition.to(frog, { time=2000, y=c,onComplete=animUp4})  
 end  
  
 local animUp2 = function(d)  
  
 ballTween = transition.to(frog, { time=2000, x=d, onComplete=animUp3})  
  
 end  
  
 local animUp = function(e)   
  
 ballTween = transition.to(frog, { time=2000,y=e,onComplete=animUp2})   
  
 end   
 ballTween = transition.to( frog, { time=2000, x=a,onComplete=animUp})   
  
 end   
  
 end   
  
---I want to try to change the value of x and y for the different functions so I tried this and none of it works.  
  
 up=ballAni() --  
  
 up.animUP(100) -- e would be 100 in the animuP function thus y=100  
  
 up.animuP2(200) -- d would be 200 in the aniUmp2 function thus x=200   
  

– Is there a way to do this? --Thank you for the help

[import]uid: 104131 topic_id: 33869 reply_id: 333869[/import]

You need something like this:

ballTween = transition.to( frog, { time=2000, x=a, onComplete= function() animUp(10) end } )  

Instead of giving “onComplete” the name of an existing function, you create an “anonymous function” right there and then. In the contents of that function you can then call your other functions with a parameter.
Edit: The formatting was skewed horribly so I’ve put it all onto one line.
[import]uid: 84115 topic_id: 33869 reply_id: 134626[/import]

Oh and I presume your functions weren’t working because if we take your example

local animUp = function(e)   
 --onComplete will call animUp2, which expects an argument "d", but it is not given one here.   
 ballTween = transition.to(frog, { time=2000,y=e,onComplete=animUp2})   
end   

In my experience, failed onComplete functions either mess the whole thing up entirely, or ignore the transition and snap immediately to the end position. [import]uid: 84115 topic_id: 33869 reply_id: 134628[/import]

@AlanPlantPot. Thank you for the quick response. My biggest problem is that I want to alternate/chnge the x or y values in the transition for each function. I want to be able to do this fom outside of the function ballAni(). Can’t seem to figure it out. For example changing the value of x=a to x=15 and so on. Thanks again for your help.

[code] local function ballAni(a)

local animUp4 = function(b)

ballTween = transition.to(frog, { time=2000, x=b, onComplete=hidepath})

end

local animUp3 = function©

ballTween = transition.to(frog, { time=2000, y=c,onComplete=animUp4})
end

local animUp2 = function(d)

ballTween = transition.to(frog, { time=2000, x=d, onComplete=animUp3})

end

local animUp = function(e)

ballTween = transition.to(frog, { time=2000,y=e,onComplete=animUp2})

end
ballTween = transition.to( frog, { time=2000, x=a,onComplete=animUp})

end

end

[/code]

[import]uid: 104131 topic_id: 33869 reply_id: 134652[/import]

You need something like this:

ballTween = transition.to( frog, { time=2000, x=a, onComplete= function() animUp(10) end } )  

Instead of giving “onComplete” the name of an existing function, you create an “anonymous function” right there and then. In the contents of that function you can then call your other functions with a parameter.
Edit: The formatting was skewed horribly so I’ve put it all onto one line.
[import]uid: 84115 topic_id: 33869 reply_id: 134626[/import]

Oh and I presume your functions weren’t working because if we take your example

local animUp = function(e)   
 --onComplete will call animUp2, which expects an argument "d", but it is not given one here.   
 ballTween = transition.to(frog, { time=2000,y=e,onComplete=animUp2})   
end   

In my experience, failed onComplete functions either mess the whole thing up entirely, or ignore the transition and snap immediately to the end position. [import]uid: 84115 topic_id: 33869 reply_id: 134628[/import]

@AlanPlantPot. Thank you for the quick response. My biggest problem is that I want to alternate/chnge the x or y values in the transition for each function. I want to be able to do this fom outside of the function ballAni(). Can’t seem to figure it out. For example changing the value of x=a to x=15 and so on. Thanks again for your help.

[code] local function ballAni(a)

local animUp4 = function(b)

ballTween = transition.to(frog, { time=2000, x=b, onComplete=hidepath})

end

local animUp3 = function©

ballTween = transition.to(frog, { time=2000, y=c,onComplete=animUp4})
end

local animUp2 = function(d)

ballTween = transition.to(frog, { time=2000, x=d, onComplete=animUp3})

end

local animUp = function(e)

ballTween = transition.to(frog, { time=2000,y=e,onComplete=animUp2})

end
ballTween = transition.to( frog, { time=2000, x=a,onComplete=animUp})

end

end

[/code]

[import]uid: 104131 topic_id: 33869 reply_id: 134652[/import]