Advertisement
MrPipa

ComputerCraft Turtle Wall Builder

Mar 2nd, 2016
869
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.49 KB | None | 0 0
  1. --Author: MrPipa
  2. --Place the turtle in the lower left corner in front of the wall
  3. --Usage: <Name of the program> <height> <width>
  4.  
  5. local x,y = ...
  6. h = tonumber(x)
  7. l = tonumber(y)
  8.  
  9. --Preparations
  10.     --Input check:
  11.     print("Your input was:\nHeight: " .. h .. "\nWidth: " .. l)
  12.     if h < 1 then
  13.         print("Usage: wall <height> <width>")
  14.         return
  15.     end
  16.     if l < 1 then
  17.         print("Usage: wall <height> <width>")
  18.         return
  19.     end
  20. print("Input ok!\nMaking necessary preparations...")
  21.  
  22.     --Minor fixes...
  23.     slot = 0
  24.     l = l - 1
  25.  
  26.     --Moving into place:
  27.     turtle.forward()
  28.     turtle.up()
  29.     turtle.turnRight()
  30.     while turtle.getItemCount() == 0 do
  31.         if turtle.getSelectedSlot() == 16 then
  32.             print("ERROR: Out of materials!")
  33.             return
  34.         end
  35.         turtle.select(turtle.getSelectedSlot() + 1)
  36.     end
  37.     turtle.placeDown()
  38.  
  39. print("Preparations complete!")
  40.  
  41. --Building
  42. print("Building...")
  43. for i = 1,h do
  44.     for i = 1,l do
  45.         turtle.forward()
  46.         while turtle.getItemCount() == 0 do
  47.             if turtle.getSelectedSlot() == 16 then
  48.                 print("ERROR: Out of materials!")
  49.                 return
  50.             end
  51.             turtle.select(turtle.getSelectedSlot() + 1)
  52.         end
  53.         turtle.placeDown()
  54.     end
  55.    
  56.     if i < h then
  57.     print("Moving to next level...")
  58.         turtle.turnLeft()
  59.         turtle.turnLeft()
  60.         turtle.up()
  61.         while turtle.getItemCount() == 0 do
  62.             if turtle.getSelectedSlot() == 16 then
  63.                 print("ERROR: Out of materials!")
  64.                 return
  65.             end
  66.             turtle.select(turtle.getSelectedSlot() + 1)
  67.         end
  68.         turtle.placeDown()
  69.     end
  70. end
  71. print("All done!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement