Please help. I’ve been scripting for a couple of months. I’m tring to move a object (man) in
transitions of 10 in the direction of the variable (direction). on completing its move, it checks the direction again
and repeats the process. the idea been that it can move correctly around a maze without hitting the walls…
For instance a player is moving the man up within the maze, they press move right…
after each transition a function checks all possible directions in can move in,
if it can’t move right it keeps moving up until it has the option to move right.
I hope this makes some sort of sense, i’m just stuck on the move, check direction, repeat,
I can then manipulate the direction variable accordingly
i’ve tried many ideas, this is the latest:-
local direction local newDirection local man = display.newImageRect( "images/man.png" ,10 ,10 ) man.x=100; man.y=100 local right = display.newImageRect( "images/button.png" ,20 ,20 ) right.x=250; right.y=440 right.id = "rightButton" local left = display.newImageRect( "images/button.png" ,20 ,20 ) left.x=200; left.y=440 left.id = "leftButton" local function checkDirection( event ) print (direction) if direction == 1 then newDirection = man.x newDirection = newDirection+10 transition.moveto( man, { x=newDirection, y=0, time=200 } ) end end -- direction 1 = right / direction 2 = left -- SET DIRECTION RIGHT function right:touch( event ) if event.phase == "began" then print( "You touched the right button!" ) direction = 1 return true end end -- SET DIRECTION LEFT function left:touch( event ) if event.phase == "began" then print( "You touched the left button!" ) direction = 2 return true end end right:addEventListener( "touch", right ) left:addEventListener( "touch", left ) Runtime:addEventListener( "enterFrame", checkDirection )