Transition To Problem with OnComplete Functions

Hi Guys

I have a platform in a game that I want to move up and down.  I have the following code: -

local transitionListener2 = function( obj )

    

    if obj.transitionRepeat == “1” then

                 transition.to( obj, { time=tonumber(obj.transitionTime),   y=tonumber(obj.y + obj.transitionY), x=tonumber(obj.x+obj.transitionX), onComplete=transitionListener } )

    end

end

local transitionListener = function( obj )

    

    if obj.transitionRepeat == “1” then

                 transition.to( obj, { time=tonumber(obj.transitionTime),   y=tonumber(obj.y - obj.transitionY), x=tonumber(obj.x-obj.transitionX), onComplete=transitionListener2 } )

    end

end

transition.to( ledge[j], { time=tonumber(ledge[j].transitionTime),   y=tonumber(ledge[j].y + ledge[j].transitionY), x=tonumber(ledge[j].x + ledge[j].transitionX), onComplete=transitionListener

This works fine for the first movement and the second and the third.  But on transitionListener2 I am referencing a function onComplete which is below this call.  This appears to stop the process in its tracks as it cannot see the function call.

Is there a way in LUA to make sure that functions references above in code can be made visible?

Sorry everyone - just found the answer to this!  Stop declaring my functions as local!!!  

It cannot be the best answer. Local brings only good things for your app :stuck_out_tongue:

You must use forward declaration, like:

local transitionListener local transitionListener2 transitionListener2 = function( obj ) --- your code end transitionListener = function( obj ) --- your code end

Sorry everyone - just found the answer to this!  Stop declaring my functions as local!!!  

It cannot be the best answer. Local brings only good things for your app :stuck_out_tongue:

You must use forward declaration, like:

local transitionListener local transitionListener2 transitionListener2 = function( obj ) --- your code end transitionListener = function( obj ) --- your code end