thorax232

Computer Craft - Place Torches

Jun 21st, 2014
607
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.25 KB | None | 0 0
  1. local count = 1
  2. local length
  3. local width
  4.  
  5. function forward(n)
  6.     for i=1,n do
  7.         if turtle.detect() then
  8.             turtle.dig()
  9.         end
  10.         turtle.forward()
  11.     end
  12. end
  13.  
  14. function turnAround()
  15.     turtle.turnRight()
  16.     turtle.turnRight()
  17. end
  18.  
  19. function placeTorch()
  20.         turtle.select(1)
  21.         turnAround()
  22.         turtle.place()
  23.         turnAround()
  24. end
  25.  
  26. function firstTorch()
  27.     forward(1)
  28.     placeTorch()
  29. end
  30.  
  31. function buildRow()
  32.     for i=1,length do
  33.         forward(12)
  34.         placeTorch()
  35.     end
  36. end
  37.  
  38. function nextRow()
  39.     if count % 2 == 0 then -- Turn right for even numbered rows
  40.         forward(5)
  41.         turtle.turnRight()
  42.         forward(8)
  43.         placeTorch()
  44.         turtle.turnRight()
  45.         forward(1)
  46.         turtle.turnRight()
  47.         forward(1)
  48.         turtle.turnLeft()
  49.     else -- Turn left for odd numbered rows
  50.         forward(5)
  51.         turtle.turnLeft()
  52.         forward(8)
  53.         placeTorch()
  54.         turtle.turnLeft()
  55.         forward(1)
  56.         turtle.turnLeft()
  57.         forward(1)
  58.         turtle.turnRight()
  59.     end
  60.     count = count + 1
  61. end
  62.  
  63. function driver()
  64.     for i = 1,width do
  65.         buildRow()
  66.         if i < width then -- Avoids extra row at end
  67.             nextRow()
  68.         end
  69.     end
  70. end
  71.  
  72. turtle.select(1) -- Select torches
  73.  
  74. print("How far forward? (length)")
  75. length = tonumber(read()) / 18
  76. print("How far left? (width)")
  77. width = tonumber(read()) / 8
  78.  
  79. firstTorch()
  80. driver()
Advertisement
Add Comment
Please, Sign In to add comment