Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function moveTo(x, z)
- local currX, currZ = 0, 0
- local facing = 0 -- 0 = north, 1 = east, 2 = south, 3 = west
- -- turn to face the positive X direction
- while facing ~= 1 do
- turtle.turnRight()
- facing = (facing + 1) % 4
- end
- -- move the turtle along the positive X axis until it reaches the target X coordinate
- while currX ~= x do
- if x > currX then
- turtle.forward()
- currX = currX + 1
- else
- turtle.back()
- currX = currX - 1
- end
- end
- -- turn to face the positive Z direction
- while facing ~= 0 do
- turtle.turnRight()
- facing = (facing + 1) % 4
- end
- -- move the turtle along the positive Z axis until it reaches the target Z coordinate
- while currZ ~= z do
- if z > currZ then
- turtle.forward()
- currZ = currZ + 1
- else
- turtle.back()
- currZ = currZ - 1
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement