I’m working on a kind of Fall Down type game and I’ve created 2 randomly generating blocks, the problem is, while the first block finishes moving, the second one doesn’t repeat its movement. It stops moving and stops printing “restarted” upon finishing. Here’s the code: (I’m aware it’s ugly and inefficient, I’m a beginner and made the whole thing in ~3 hours)
[lua]
–code for movement of first tile
–repeat movement when movement has completed
function completeMove()
transition.to( floorTile, { time=5, x=math.random( 30, 300 ), y=display.contentHeight / 1, onComplete=moveTile} )
print(“move completed”)
end
–the actually movement of the first tile
function moveTile()
if score <=150 then
if floorTile.isMoving == true then
transition.to( floorTile, {time=1500, y=0, onComplete=completeMove } )
print(“moving”)
elseif floorTile.isMoving == false then
transition.to( floorTile, { display.remove(floorTile) } )
end
end
end
–code for second tile’s movement
–code for repeat
function completeT()
transition.to( floorTile2, { time=5, x=math.random( 30, 300 ), y=display.contentHeight / 1, onComplete=moveT } )
print(“restarted”)
end
–the movement of the second tile
function moveT()
if score <= 150 then
if floorTile.isMoving == true then
transition.to( floorTile2, {time=1500, y=0, onComplete=completeT } )
print(“2 is moving”)
elseif floorTile.isMoving == false then
transition.to( floorTile2, { display.remove(floorTile) } )
end
end
end
[/lua]