Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- startX, startY, startZ = gps.locate()
- function currentLocation()
- currentX, currentY, currentZ = gps.locate()
- end
- function facingDirection()
- turtle.forward()
- currentLocation()
- if currentX > startX then
- currentDirection = "east"
- end
- if currentX < startX then
- currentDirection = "west"
- end
- if currentZ > startZ then
- currentDirection = "north"
- end
- if currentZ < startZ then
- currentDirection = "south"
- end
- print("Facing: "..currentDirection)
- end
- function turnDirection(directionToFace)
- -- Case east
- if directionToFace == "east" then
- if currentDirection == "north" then
- turtle.turnRight()
- elseif currentDirection == "east" then
- --Do nothing
- elseif currentDirection == "south" then
- turtle.turnRight()
- turtle.turnRight()
- elseif currentDirection == "west" then
- turtle.turnLeft()
- end
- end
- --Case east
- --Case west
- if directionToFace == "west" then
- if currentDirection == "north" then
- turtle.turnLeft()
- elseif currentDirection == "east" then
- turtle.turnRight()
- turtle.turnRight()
- elseif currentDirection == "south" then
- turtle.turnLeft()
- elseif currentDirection == "west" then
- --Do nothing
- end
- end
- --Case west
- --Case north
- if directionToFace == "north" then
- if currentDirection == "north" then
- --Do nothing
- elseif currentDirection == "east" then
- turtle.turnRight()
- elseif currentDirection == "south" then
- turtle.turnRight()
- turtle.turnRight()
- elseif currentDirection == "west" then
- turtle.turnLeft()
- end
- end
- --Case north
- --Case south
- if directionToFace == "south" then
- if currentDirection == "north" then
- turtle.turnRight()
- turtle.turnRight()
- elseif currentDirection == "east" then
- turtle.turnLeft()
- elseif currentDirection == "south" then
- --Do nothing
- elseif currentDirection == "west" then
- turtle.turnRight()
- end
- end
- --Case south
- end
- facingDirection()
- turnDirection(south)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement