Functions that are executed one after another

Hello 

I want a routine that allows me to call a function and then another, but that is only run once the first is finished. 

This code does not work. 

Thanks for your help


local free=true

rect=display.newRect(0,0,100,100)

function mam(num)

    libre = false

    local function exit ()

        free=true

        return 

    end 

    if libre == false then

        transition.to( rect, {time=1000, x=num, onComplete=exit} )

    end

end

repeat mam(300) until free == true

repeat mam(2) until free == true

sorry. In the code when said libre=false it is free=false

[lua]

rect=display.newRect(0,0,100,100)

transition.to( rect, {time=1000, x=200, onComplete=  function() transition.to( rect, {time=1000, x=2} end } )

[/lua]

Something like that should work (didn’t test the exact syntax), plus code after that keeps running while waiting. You can extend the idea like that in code, but it gets unwieldy/cryptic quickly. Probably best off to go with separate lua functions for completion handlers and have them rinse, and repeat the idea with perhaps more separate completion handlers at each separate stage of some sequence (especially for longer sequences, with lots of parameters/variables between them).

Thank You for your aswer, but the think that I want is, a function that waits that ended other funtions  

sorry. In the code when said libre=false it is free=false

[lua]

rect=display.newRect(0,0,100,100)

transition.to( rect, {time=1000, x=200, onComplete=  function() transition.to( rect, {time=1000, x=2} end } )

[/lua]

Something like that should work (didn’t test the exact syntax), plus code after that keeps running while waiting. You can extend the idea like that in code, but it gets unwieldy/cryptic quickly. Probably best off to go with separate lua functions for completion handlers and have them rinse, and repeat the idea with perhaps more separate completion handlers at each separate stage of some sequence (especially for longer sequences, with lots of parameters/variables between them).

Thank You for your aswer, but the think that I want is, a function that waits that ended other funtions