Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function moveTo(x, z)
- local currX, currY, currZ = gps.locate()
- if not currX then
- print("Unable to get current location.")
- return
- end
- local diffX = x - currX
- local diffZ = z - currZ
- if diffX > 0 then
- turtle.turnRight()
- elseif diffX < 0 then
- turtle.turnLeft()
- end
- while diffX ~= 0 do
- if diffX > 0 then
- turtle.forward()
- diffX = diffX - 1
- elseif diffX < 0 then
- turtle.back()
- diffX = diffX + 1
- end
- end
- if diffZ > 0 then
- turtle.turnLeft()
- elseif diffZ < 0 then
- turtle.turnRight()
- end
- while diffZ ~= 0 do
- if diffZ > 0 then
- turtle.forward()
- diffZ = diffZ - 1
- elseif diffZ < 0 then
- turtle.back()
- diffZ = diffZ + 1
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement