Sequence of functions

Hello, forgive my google translation

Can somebody help me?

I am trying to make this sequence of functions work but I can not link move1 with move2.

Does anyone know how to do it?

local function mover2() local bajarElevador = function() if elevador.y \< 3000 then elevador.y = elevador.y + 1 end end Runtime:addEventListener( "enterFrame", bajarElevador ) end local function mover1() local subirElevador = function() if elevador.y \> 1900 then elevador.y = elevador.y - 1 elevador.onComplete = mover2 end end Runtime:addEventListener( "enterFrame", subirElevador ) end mover1()

I’m not sure I understood your question correctly but I think you’re asking for something like this:

local mover1,mover2 local elevador = display.newRect( 160, 250, 20, 20) mover1 = function() print("I'm mover1") transition.to(elevador, {time=3000, y=350, onComplete=mover2}) end mover2 = function() print("I'm mover2") transition.to(elevador, {time=3000, y=150, onComplete=mover1}) end mover2()

Note:I used “transition.to” to move “elevador” you can also use the runtime events but if you just have to do up and down I think that even with the transactions you’ll be fine.

If you use runtime events,  remember to remove them when you do not need them anymore!

@maximo97 supplied a great solution.  This slight change will make it a little safer, should you later delete the elevator object:

local mover1,mover2 local elevator = display.newRect( 160, 250, 20, 20) elevator.onComplete1 = function( self ) print("I'm mover1") self.onComplete = self.onComplete2 transition.to( self, { time = 3000, y = 350, onComplete = self } ) end elevator.onComplete2 = function( self ) print("I'm mover2") self.onComplete = self.onComplete1 transition.to( self, { time = 3000, y = 150, onComplete = self } ) end -- Cancel transition when elevator is deleted function elevator.finalize( self ) transition.cancel( self ) end elevator:addEventListener( "finalize" ) self:onComplete2()

Tip: If this is just a visual effect you’re good to go, but if you add a physics body to the elevator and hope it will act like a moving platform that pushes/raises/lowers objects, this will not work.

Thanks for answering people,

I have to do it with enterFrame because with transition.to, when the elevator moves, the doll stays behind

I’m not sure I understood your question correctly but I think you’re asking for something like this:

local mover1,mover2 local elevador = display.newRect( 160, 250, 20, 20) mover1 = function() print("I'm mover1") transition.to(elevador, {time=3000, y=350, onComplete=mover2}) end mover2 = function() print("I'm mover2") transition.to(elevador, {time=3000, y=150, onComplete=mover1}) end mover2()

Note:I used “transition.to” to move “elevador” you can also use the runtime events but if you just have to do up and down I think that even with the transactions you’ll be fine.

If you use runtime events,  remember to remove them when you do not need them anymore!

@maximo97 supplied a great solution.  This slight change will make it a little safer, should you later delete the elevator object:

local mover1,mover2 local elevator = display.newRect( 160, 250, 20, 20) elevator.onComplete1 = function( self ) print("I'm mover1") self.onComplete = self.onComplete2 transition.to( self, { time = 3000, y = 350, onComplete = self } ) end elevator.onComplete2 = function( self ) print("I'm mover2") self.onComplete = self.onComplete1 transition.to( self, { time = 3000, y = 150, onComplete = self } ) end -- Cancel transition when elevator is deleted function elevator.finalize( self ) transition.cancel( self ) end elevator:addEventListener( "finalize" ) self:onComplete2()

Tip: If this is just a visual effect you’re good to go, but if you add a physics body to the elevator and hope it will act like a moving platform that pushes/raises/lowers objects, this will not work.

Thanks for answering people,

I have to do it with enterFrame because with transition.to, when the elevator moves, the doll stays behind