Advertisement
civilwargeeky

FlatSurface.lua

Oct 31st, 2014
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.25 KB | None | 0 0
  1. --flat surface
  2.  
  3. local slot = 1
  4. local turnFunc = turtle.turnRight
  5.  
  6. local tArgs = {...}
  7. if (tArgs[1] or ""):lower() == "left" then
  8.   turnFunc = turtle.turnLeft
  9. end
  10.  
  11. local function placeDo(moveFunc, placeFunc)
  12.   while turtle.getItemCount(slot) == 0 do
  13.     slot = slot + 1
  14.     if slot > 16 then error("Out of stuff") end
  15.     turtle.select(slot)
  16.   end
  17.   return moveFunc(), placeFunc()
  18. end
  19.  
  20. turtle.select(1)
  21. turtle.turnLeft()
  22. turtle.turnLeft()
  23. local switch = false --Whether or not it is above the layer
  24. while true do
  25.   while placeDo(turtle.back, turtle.place) do end --Will keep going back until the end of the row
  26.   turnFunc()
  27.   if not placeDo(turtle.back, turtle.place) then --If can't turn will end
  28.     switch = true
  29.     if not (placeDo(turtle.up, turtle.placeDown) and turtle.back()) then error("Program Stuck") end --Goes up, back, then errors if either fails, and stops the second from going if the first fails
  30.   end
  31.   turnFunc()
  32.   if switch then
  33.     if not (turtle.back() and turtle.down()) then error("Program Over") end --Goes back into the regular
  34.     switch = false
  35.   end
  36.  
  37.   if turnFunc == turtle.turnRight then --Switch the turn function for next row
  38.     turnFunc = turtle.turnLeft
  39.   else
  40.     turnFunc = turtle.turnRight
  41.   end
  42. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement