Advertisement
Guest User

Stairs

a guest
Apr 3rd, 2020
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.55 KB | None | 0 0
  1. --To build stairs, need width of stairwell, height of stairwell, depth of stairwell
  2. local tArgs = {...}
  3.  
  4. -- Deal with arguments and variables
  5. local args = tArgs
  6. local curr_height,curr_width,curr_depth = 1
  7. local direction = nil
  8. local dig = nil
  9.  
  10. -- error handling
  11. local syntax_error="Invalid syntax.  Try using:\n stairs X Y Z\n X = Height of stairwell\n Y = Width of stairwell\n Z = Depth of stairwell\n\nX, Y, and Z must be integers"
  12.  
  13. -- right # & type of arguments?
  14. function initialize()
  15.     if #args ~= 3 or tonumber(value)==nil then
  16.             return print(syntax_error)
  17.            
  18.     else
  19.             -- set measurements
  20.             local height = tonumber(args[1])
  21.             local width = tonumber(args[2])
  22.             local depth = tonumber(args[3])
  23.  
  24.             -- get direction
  25.             print("<U>p or <D>own?")
  26.             local input=string.lower(read())
  27.             responses = {"up"=true,"down"=true,"u"=true,"d"=true}
  28.  
  29.             -- return lowercase first character to determine stairwell direction
  30.             if responses.input then
  31.                     direction = string.sub(input,1,1)
  32.                     return direction
  33.             end
  34.     end
  35.  
  36.  
  37. -- dig one column to specified height
  38. function column(direction, height)
  39.         if direction == "u" then
  40.                 while curr_height < height do
  41.                         turtle.digUp()
  42.                         turtle.moveUp()
  43.                         curr_height = curr_height + 1
  44.                 end
  45.                 while curr_height ~=1 do
  46.                         turtle.moveDown()
  47.                         curr_height = curr_height - 1
  48.                 end
  49.         else
  50.                 while curr_height < height - 1 do
  51.                         turtle.digDown()
  52.                         turtle.digUp()
  53.                         turtle.moveUp()
  54.                         curr_height = curr_height + 1
  55.                 end
  56.         end
  57.         return
  58. end
  59.  
  60. -- digs riser to width and height
  61. function digriser(width)
  62.         for col=1, width, 1 do
  63.                 column()
  64.                 turtle.turnRight()
  65.                 turtle.moveForward()
  66.                 turtle.turnLeft()
  67.         end
  68.         turtle.turnLeft()
  69.         turtle.turnLeft()
  70.         turtle.moveForward(width - 1)
  71.         turtle.turnRight()
  72.         turtle.dig()
  73.         turtle.moveForward()
  74.         return
  75. end
  76.  
  77. -- digs out the stairs
  78. function digstairs(depth)
  79.         while curr_depth ~= depth do
  80.                 digriser(width)
  81.                 curr_dept = curr_depth + 1
  82.         end
  83. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement