how to start a function when ended another function

i want call a functions different, following a path.

This is an example, where a rectangle has follow a path.

Some one person have a idea

Thank You

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

rec.x = 100

rec.y = 100

local function moverX( num )

    transition.to(rec, {time = 500, x = rec.x+num})

end

local function moverY( num )

    transition.to(rec, {time = 500, y = rec.y+num})

end

moverX (34)

moverY (50)

moverX (100)

moverY (-30)

Sorry I don’t understand the question, can you clarify?

Sorry, that was an example. I want to call different functions one after the other. When a finish to start the other, had thought of an array with function names lso does not work.

Example would be:

function (eating)

function (run)

function (sleep).

and I want to call eg (eating, eating, sleeping, running) or in another town (sleep, sleep eating).

I hope I explained…

Hello people, after write my ask I find the answer. I put the code in case it is interesting for any persons, Thank you

rec = display.newRect(0,0,100,100) rec.x = 100 rec.y = 100

local cont = 1

local resp = 0

local function finCiclo ()

    resp=0

end

local function moverX( num )

    resp =1

    transition.to(rec, {time = 500, x = rec.x+num, onComplete = finCiclo})

end

local function moverY( num )

    resp =1

    transition.to(rec, {time = 500, y = rec.y+num, onComplete = finCiclo})

end

local function movAcciones (vector)

    local vec = vector

    local function vector (event)

        print (vec[cont], vec [cont+1])

        if vec[cont] == 0 then timer.cancel (event.source) end

        if vec[cont] == 1 and resp == 0 then moverX (vec[cont+1]) cont = cont +2 end

        if vec[cont] == 2 and resp == 0 then moverY (vec[cont+1]) cont = cont +2 end

    end

    timer.performWithDelay( 1000, vector, 0 )

end

local vec = {1,45,2,30,2,-15,1,100,0}

movAcciones (vec)

Sorry I don’t understand the question, can you clarify?

Sorry, that was an example. I want to call different functions one after the other. When a finish to start the other, had thought of an array with function names lso does not work.

Example would be:

function (eating)

function (run)

function (sleep).

and I want to call eg (eating, eating, sleeping, running) or in another town (sleep, sleep eating).

I hope I explained…

Hello people, after write my ask I find the answer. I put the code in case it is interesting for any persons, Thank you

rec = display.newRect(0,0,100,100) rec.x = 100 rec.y = 100

local cont = 1

local resp = 0

local function finCiclo ()

    resp=0

end

local function moverX( num )

    resp =1

    transition.to(rec, {time = 500, x = rec.x+num, onComplete = finCiclo})

end

local function moverY( num )

    resp =1

    transition.to(rec, {time = 500, y = rec.y+num, onComplete = finCiclo})

end

local function movAcciones (vector)

    local vec = vector

    local function vector (event)

        print (vec[cont], vec [cont+1])

        if vec[cont] == 0 then timer.cancel (event.source) end

        if vec[cont] == 1 and resp == 0 then moverX (vec[cont+1]) cont = cont +2 end

        if vec[cont] == 2 and resp == 0 then moverY (vec[cont+1]) cont = cont +2 end

    end

    timer.performWithDelay( 1000, vector, 0 )

end

local vec = {1,45,2,30,2,-15,1,100,0}

movAcciones (vec)