Created
August 14, 2015 12:38
-
-
Save popkirby/8ea371e526da4f3d1018 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
forward = "forward" | |
back = "back" | |
up = "up" | |
down = "down" | |
left = "left" | |
right = "right" | |
-- | |
function turn(dir) | |
if dir == left then | |
return turtle.turnLeft() | |
elseif dir == right then | |
return turtle.turnRight() | |
elseif dir == back then | |
turtle.turnLeft() | |
return turtle.turnLeft() | |
end | |
end | |
-- dig | |
function dig(dir) | |
local ret = true | |
if dir == forward then | |
return turtle.dig() | |
elseif dir == back then | |
turn(back) | |
ret = turtle.dig() | |
turn(back) | |
return ret | |
elseif dir == up then | |
return turtle.digUp() | |
elseif dir == down then | |
return turtle.digDown() | |
elseif dir == left then | |
turn(left) | |
ret = turtle.dig() | |
turn(right) | |
return ret | |
elseif dir == right then | |
turn(right) | |
ret = turtle.dig() | |
turn(left) | |
return ret | |
end | |
return false | |
end | |
-- move | |
function move(dir, keepDir) | |
local ret = false | |
if dir == forward then | |
return turtle.forward() | |
elseif dir == back then | |
return turtle.back() | |
elseif dir == up then | |
return turtle.up() | |
elseif dir == down then | |
return turtle.down() | |
elseif dir == left then | |
turn(left) | |
ret = turtle.forward() | |
if keepDir then | |
turn(right) | |
end | |
return ret | |
elseif dir == right then | |
turn(right) | |
ret = turtle.forward() | |
if keepDir then | |
turn(left) | |
end | |
return ret | |
end | |
end | |
-- vim: ft=lua |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment