Simple Loop transition.to

Hi
How to make a simple loop… I want to transition a object from A to B and then from B to A in loop.
I made something like this

 local moveboard = function()  
 local movedown = function()  
 transition.to(object, { 200, y = 200, onComplete = moveboard} )  
 end  
 transition.to(object, {200 , y =300, onComplete= movedown } )  
 end  
moveboard()  

It’s moving but it stops !!!
by the way if you have few object on a screen that should move I suppose to use transition or is different way for many objects ?
Thank you [import]uid: 13156 topic_id: 5947 reply_id: 305947[/import]

I know that I can use :

  
 local moveobject = function(event)  
  
 object.x = object.x +1  
 end  
  
Runtime:addEventListener("enterFrame" , moveobject)  

but I don’t know how to move back to place when object starts moving (loop ) [import]uid: 13156 topic_id: 5947 reply_id: 20395[/import]

This doesn’t move but it should give you the general idea…
[blockcode]
function btnPlayOut()

trnbtnPlay = transition.to( btnPlay, { time=400, xScale=1.05, yScale=0.95, onComplete=btnPlayIn } )

end

function btnPlayIn()

trnbtnPlay = transition.to( btnPlay, { time=400, xScale=0.95, yScale=1.05, onComplete=btnPlayOut } )

end

[/blockcode]

The to kick it off in the first place…

[blockcode]
trnbtnPlay = transition.to( btnPlay, { time=400, xScale=0.95, yScale=1.05, onComplete=btnPlayOut} )

[/blockcode] [import]uid: 9371 topic_id: 5947 reply_id: 20394[/import]

Thanks dweezil but the same result STOPS ???! [import]uid: 13156 topic_id: 5947 reply_id: 20399[/import]

You had the right idea in the first place, but defining one function inside another like that messes up the scope. Just off the top of my head, does this work?

function moveboard() transition.to(object, {200, y = 300, onComplete = movedown}) end function movedown() transition.to(object, {200, y = 200, onComplete = moveboard}) end moveboard() [import]uid: 12108 topic_id: 5947 reply_id: 20465[/import]

Thanks jhocking but unfortunately no … :frowning: the same.
hmmm I don’t know why ? Any Idea ? This two functions are inside w function drawLevel… but I think is not a problem… [import]uid: 13156 topic_id: 5947 reply_id: 20485[/import]

My (and jhockings) code is good and works here!

So does it move to and back then stop? [import]uid: 9371 topic_id: 5947 reply_id: 20556[/import]

exactly … :slight_smile: [import]uid: 13156 topic_id: 5947 reply_id: 20565[/import]

Ah I think I know why…please paste your current code… [import]uid: 9371 topic_id: 5947 reply_id: 20566[/import]

Ok Let’s take a look :

[code]

local drawLevel = function()






board = display.newImage(“board.png”)
board.x = 50
board.y = 200
board.rotation = 90
levelFourGroup:insert(board)
physics.addBody(board, “static”, {density = 1.0, friction = 0.3, bounce = 0.4 })
local moveback = function()
local moveboard = function()
transition.to(board, { 100, y = 300, onComplete = moveback})
end
transition.to(board, { 100, y = 200, onComplete = moveboard})
end
moveback()





end

drawlevel()

[/code] [import]uid: 13156 topic_id: 5947 reply_id: 20567[/import]

Change it to this

[blockcode]

function moveback()
transition.to(board, {y = 300, onComplete = moveboard})
end

function moveboard()
transition.to(board, {y = 200, onComplete = moveback})
end

moveboard()
[/blockcode] [import]uid: 9371 topic_id: 5947 reply_id: 20568[/import]

Yeeeee THANK YOU dweezil and jhocking… my solution is ok too the problem was with local… if the function is global is ok.
You know why ?
[import]uid: 13156 topic_id: 5947 reply_id: 20571[/import]

Its to do with scope, the way you had it one function was inside another and as it was local then one couldn’t ‘see’ the other. [import]uid: 9371 topic_id: 5947 reply_id: 20574[/import]

simple :slight_smile: Thanks a lot [import]uid: 13156 topic_id: 5947 reply_id: 20575[/import]

actually you probably want them as local functions. use forward references

[lua]local moveboard

local function moveback()
transition.to(board, {y = 300, onComplete = moveboard})
end

function moveboard() – it’s still local
transition.to(board, {y = 200, onComplete = moveback})
end

moveboard()[/lua]

or

[lua]local moveboard
local moveback

function moveback()
transition.to(board, {y = 300, onComplete = moveboard})
end

function moveboard()
transition.to(board, {y = 200, onComplete = moveback})
end[/lua]
[import]uid: 6645 topic_id: 5947 reply_id: 21052[/import]

Works perfekt, as I said another step forward :slight_smile:
Thanks [import]uid: 13156 topic_id: 5947 reply_id: 21132[/import]