Advertisement
Guest User

buildwall

a guest
Sep 16th, 2014
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.02 KB | None | 0 0
  1. answer = "not yes"
  2. i = 1
  3.  
  4. print("If you wish to build a wall and not a 4 sided room enter the width as wall. The smallest room this program can make is 3 x 3.")
  5.  
  6. while answer ~= "yes" do
  7.   answer = "not yes"
  8.   write("Enter the height: ")
  9.   h = read()
  10.   write("Enter the length: ")
  11.   l = read()
  12.   write("Enter the width: ")
  13.   w = read()
  14.   print("You entered your height as ", h," your length as ", l," and your width as ", w,".")
  15.   print("Is this correct?")
  16.   if w ~= "wall" then
  17.     while (answer ~= "yes") and (answer ~= "no") do
  18.       answer = read()
  19.       if answer == "yes" then
  20.         print("This room will cost about ", l*h*2+w*h*2-4*h," blocks.")
  21.       elseif answer == "no" then
  22.         print("Please try again.")
  23.       else
  24.         print("I don't understand ", answer,". Please enter yes or no.")
  25.       end
  26.     end
  27.   else
  28.     while (answer ~= "yes") and (answer ~= "no") do
  29.       answer = read()
  30.       if answer == "yes" then
  31.         print("Wall will cost about ", h*l," blocks.")
  32.       elseif answer == "no" then
  33.         print("Please try again.")
  34.       else
  35.         print("I don't understand ", answer,". Please enter yes or no")
  36.       end
  37.     end
  38.   end
  39. end
  40.  
  41. local function adjust()
  42.   turtle.turnRight()
  43.   turtle.forward()
  44.   turtle.turnLeft()
  45. end
  46.  
  47. local function reset()
  48.   turtle.turnRight()
  49.   turtle.back()
  50.   turtle.back()
  51. end
  52.  
  53. local function checkSlot()
  54.   while turtle.getItemCount() == 0 do
  55.     turtle.select(i)
  56.     i = i + 1
  57.     if i > 16 then
  58.       i = 1
  59.     end
  60.   end
  61.   return true
  62. end
  63.  
  64. local function makeSide()
  65.   for j = 1, h, 1 do
  66.     if checkSlot() then
  67.       turtle.place()
  68.       turtle.up()
  69.     end
  70.   end
  71.   adjust()
  72.   h = 0
  73.   while turtle.down() do
  74.     h = h + 1
  75.   end
  76. end
  77.  
  78. for n = 1, l, 1 do
  79.   makeSide()
  80. end
  81. if w == "wall" then
  82.   print("Completed Wall")
  83. else
  84.   reset()
  85.   for n = 1, w-1, 1 do
  86.     makeSide()
  87.   end
  88.   reset()
  89.   for n = 1, l-1, 1 do
  90.     makeSide()
  91.   end
  92.   reset()
  93.   for n = 1, w-2, 1 do
  94.     makeSide()
  95.   end
  96.   print("Completed Room")
  97. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement