dealingwith

Room Turtle Program

May 28th, 2017
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.00 KB | None | 0 0
  1. local tArgs = { ... }
  2.  
  3. if #tArgs ~= 3 then
  4.   print("Usage: room <l> <w> <h>")
  5.   return false
  6. end
  7.  
  8. for i=1,3 do
  9.   if tonumber(tArgs[i]) < 1 then
  10.     print("Usage: room <l> <w> <h>")
  11.     return false
  12.   end
  13. end
  14.  
  15. length = tArgs[1]
  16. width = tArgs[2]
  17. height = tArgs[3]
  18.  
  19. turtle.select(1)
  20. turtle.refuel()
  21.  
  22. if turtle.getFuelLevel() < 150 then
  23.   print("Fuel level too low.")
  24.   return false
  25. end
  26.  
  27. function findItems()
  28.   local slot = 2
  29.   while slot < 16 do
  30.     if turtle.getItemCount(slot) < 1 then
  31.       slot = slot + 1
  32.     else
  33.       turtle.select(slot)
  34.       return true
  35.     end
  36.   end
  37.   return false
  38. end
  39.  
  40. function buildRow(rowLen)
  41.   for i = 1, rowLen, 1 do
  42.     findItems()
  43.     turtle.placeDown()
  44.     turtle.forward()
  45.   end
  46. end
  47.  
  48. function buildLayer()
  49.   turtle.up()
  50.   buildRow(length)
  51.   turtle.turnRight()
  52.   buildRow(width)
  53.   turtle.turnRight()
  54.   buildRow(length)
  55.   turtle.turnRight()
  56.   buildRow(width)
  57.   turtle.turnRight()
  58. end
  59.  
  60. for i=1, height, 1 do
  61.   buildLayer()
  62. end
Advertisement
Add Comment
Please, Sign In to add comment