directionToFace = arg[1] if directionToFace == nil then print("Please provide a direction to turn to") return end -- Get the initial location 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 = "south" end if currentZ < startZ then currentDirection = "north" end turtle.back() print("Facing: "..currentDirection) end -- Start turnDirection() 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.turnLeft() elseif currentDirection == "west" then turtle.turnRight() turtle.turnRight() end currentDirection = "east" 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.turnRight() elseif currentDirection == "west" then --Do nothing end currentDirection = "west" end --Case west --Case north if directionToFace == "north" then if currentDirection == "north" then --Do nothing elseif currentDirection == "east" then turtle.turnLeft() elseif currentDirection == "south" then turtle.turnRight() turtle.turnRight() elseif currentDirection == "west" then turtle.turnRight() end currentDirection = "north" end --Case north --Case south if directionToFace == "south" then if currentDirection == "north" then turtle.turnRight() turtle.turnRight() elseif currentDirection == "east" then turtle.turnRight() elseif currentDirection == "south" then --Do nothing elseif currentDirection == "west" then turtle.turnLeft() end currentDirection = "south" end --Case south end facingDirection() turnDirection(directionToFace) -- End turnDirection()