Advertisement
ninja_axiom

BuildWall

Oct 26th, 2013
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.58 KB | None | 0 0
  1. function isEmpty(i)
  2.     if turtle.getItemCount(i)==0 then
  3.         print("Empty")
  4.         return true
  5.     end
  6. end
  7.  
  8. function shiftLeft()
  9.     turtle.turnLeft()
  10.     turtle.forward()
  11.     turtle.turnRight()
  12. end
  13.  
  14. function shiftRight()
  15.     turtle.turnRight()
  16.     turtle.forward()
  17.     turtle.turnLeft()
  18. end
  19.  
  20. function widthCheck(a, b)
  21.     if a == b then
  22.         return true
  23.     end
  24.     return false
  25. end
  26.  
  27. function shiftDirection(d)
  28.     if d == "left" then
  29.         shiftLeft()
  30.     end
  31.     if d == "right" then
  32.         shiftRight()
  33.     end
  34. end
  35.  
  36. --Main
  37.  
  38. io.write("Enter Length: ")
  39. height = tonumber(io.read())
  40. io.write("Enter Width: ")
  41. width = tonumber(io.read())
  42. io.write("Direction- left or right: ")
  43. direction = string.lower(io.read())
  44.  
  45. itemIndex = 1
  46. turtle.select(itemIndex)
  47. widthCount = 0
  48.  
  49. while true do
  50.     for i=1, height-1 do
  51.         if isEmpty(itemIndex) then
  52.             itemIndex = itemIndex + 1
  53.             turtle.select(itemIndex)
  54.         end
  55.         turtle.place()
  56.         turtle.up()
  57.     end
  58.     if isEmpty(itemIndex) then
  59.         itemIndex = itemIndex + 1
  60.         turtle.select(itemIndex)
  61.     end
  62.     turtle.place()
  63.     widthCount = widthCount+1
  64.     if widthCheck(widthCount, width) then
  65.         break
  66.     end
  67.    
  68.     shiftDirection(direction)
  69.    
  70.    
  71.    
  72.     for i=1, height-1 do
  73.         if isEmpty(itemIndex) then
  74.             itemIndex = itemIndex + 1
  75.             turtle.select(itemIndex)
  76.         end
  77.         turtle.place()
  78.         turtle.down()
  79.     end
  80.     if isEmpty(itemIndex) then
  81.         itemIndex = itemIndex + 1
  82.         turtle.select(itemIndex)
  83.     end
  84.     turtle.place()
  85.     widthCount = widthCount+1
  86.     if widthCheck(widthCount, width) then
  87.         break
  88.     end
  89.     shiftDirection(direction)
  90.  
  91. end
  92.  
  93. if (width%2) > 0 then
  94.     for i=1, height do
  95.         turtle.down()
  96.     end
  97. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement