transition.to not firing/executing properly

Hi,

I would like someone to explain to me why the following transition only executes 3 times rather than continuously as intended.

local function moveMeUp(obj) obj.movement = transition.to ( obj, {time = 3000, delta = true, y= -30, onComplete = moveMeDown} ) end local function moveMeDown(obj) obj.movement = transition.to ( obj, {time = 3000, delta = true, y= 30, onComplete = moveMeUp} ) end function scene:enterScene( event ) local group = self.view -- start item movement item.movement = transition.to ( item, {time = 3000, delta = true, y= -30, onComplete = moveMeDown} ) end

I have already overcame this issue by having nested funtions for moveMeUp and MoveMeDown. But cancelling these transitions properly and immediately is proving difficult. So i would like to know why the logic behind the sample above doesn’t work properly (only executes three times) so maybe i can fix it and make hings easier in terms of cancelling the transition.

for your reference here is my workaround:

local function moveMeDown(obj) local function moveMeUp(obj) obj.movement = transition.to ( obj, {time = 3000, delta = true, y= -30, onComplete = moveMeDown} ) end obj.movement = transition.to ( obj, {time = 3000, delta = true, y= 30, onComplete = moveMeUp} ) end

Thanks for your help.

Luay

Probably you only need to initialize the moveMeDown function above moveMeUp.

[lua]

local moveMeDown

local function moveMeUp(obj)
obj.movement = transition.to ( obj, {time = 3000, delta = true, y= -30, onComplete = moveMeDown} )
end

function moveMeDown(obj)
obj.movement = transition.to ( obj, {time = 3000, delta = true, y= 30, onComplete = moveMeUp} )
end

[/lua]

I think the workaround is cleaner though :slight_smile:

@jonjonsson: Unbelievable. Your suggestion works. Could you please explain to me why it did work? 

When Lua is reading your code from top to bottom and comes to “onComplete = moveMeDown” it still does not have that variable (function) in scope. So if you localize it above it will be in scope and then you can assign the function to the variable anywhere. I’m pretty terrible at explaining these things, google “lua scope”…

OK. Thanks so much for your help.

Probably you only need to initialize the moveMeDown function above moveMeUp.

[lua]

local moveMeDown

local function moveMeUp(obj)
obj.movement = transition.to ( obj, {time = 3000, delta = true, y= -30, onComplete = moveMeDown} )
end

function moveMeDown(obj)
obj.movement = transition.to ( obj, {time = 3000, delta = true, y= 30, onComplete = moveMeUp} )
end

[/lua]

I think the workaround is cleaner though :slight_smile:

@jonjonsson: Unbelievable. Your suggestion works. Could you please explain to me why it did work? 

When Lua is reading your code from top to bottom and comes to “onComplete = moveMeDown” it still does not have that variable (function) in scope. So if you localize it above it will be in scope and then you can assign the function to the variable anywhere. I’m pretty terrible at explaining these things, google “lua scope”…

OK. Thanks so much for your help.