solidity

advanced 3high

Jan 10th, 2013
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.47 KB | None | 0 0
  1. --3 high tunnel program
  2. -- takes length, l, r, m as argument for left, right or middle line
  3. -- fixes walls and ceiling
  4.  
  5. args = { ... }
  6.  
  7. length = tonumber(args[1])
  8. side = args[2]
  9.  
  10. function refill()
  11.     if turtle.getItemCount(1) == 0 then
  12.         for s = 16,2,-1 do
  13.             turtle.select(s)
  14.             turtle.transferTo(1)
  15.         end
  16.         turtle.select(1)
  17.     end
  18. end
  19.  
  20. function leftWall()
  21.     turtle.turnLeft()
  22.     if not turtle.detect() then
  23.         refill()
  24.         turtle.place()
  25.     end
  26.     turtle.turnRight()
  27. end
  28.  
  29. function rightWall()
  30.     turtle.turnRight()
  31.     if not turtle.detect() then
  32.         refill()
  33.         turtle.place()
  34.     end
  35.     turtle.turnLeft()
  36. end
  37.  
  38. function doFloor()
  39.     if not turtle.detectDown() then
  40.         refill()
  41.         turtle.placeDown()
  42.     end
  43. end
  44.  
  45. function doCeiling()
  46.     if not turtle.detectUp() then
  47.         refill()
  48.         turtle.placeUp()
  49.     end
  50. end
  51.  
  52. function goUp()
  53.     if turtle.detectUp() then
  54.         turtle.digUp()
  55.     end
  56.     while not turtle.up() do
  57.         sleep(1)
  58.     end
  59. end
  60.  
  61. function goDown()
  62.     if turtle.detectDown() then
  63.         turtle.digDown()
  64.     end
  65.     while not turtle.down() do
  66.         sleep(1)
  67.     end
  68. end
  69.  
  70. function goForward()
  71.     if turtle.detect() then
  72.         turtle.dig()
  73.     end
  74.     while not turtle.forward() do
  75.         sleep(1)
  76.     end
  77. end
  78.  
  79. for i = 1,length do
  80.     --floor
  81.     doFloor()
  82.     for h = 1,3 do
  83.         --walls
  84.         if side == "l" then
  85.             leftWall()
  86.         elseif side == "r" then
  87.             rightWall()
  88.         end
  89.         -- go up
  90.         if h<3 then
  91.             goUp()
  92.         end
  93.     end
  94.     doCeiling()
  95.     for h = 1,2 do
  96.         goDown()
  97.     end
  98.     if i < length then
  99.         goForward()
  100.     end
  101. end
Advertisement
Add Comment
Please, Sign In to add comment