Guest User

build

a guest
Feb 2nd, 2013
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.24 KB | None | 0 0
  1. function instructions()
  2. --here are the instructions for the program.
  3. print "please place 1 of the material you want the floor made from in slot 13"
  4. print "please place 1 of the item you want the walls made out of in slot 14"  
  5. print "please place 1 of the item you want to make the roof our of in slot 15"
  6. print "please place fuel in slot 16"
  7. end
  8. -- investigate ways to shrink this code
  9. -- this is my function to compair the
  10. -- items in the first 12 slots of the turtle
  11. -- capable of compairing to any slot in the turtle
  12. -- need to make a check to make sure it
  13. -- is not compairing to itself.
  14. function comp(t)
  15.    turtle.select(1)
  16.   if turtle.compareTo(t) == true
  17.    then s = 1
  18.    return s
  19.    else turtle.select(2)
  20.   end
  21.   if turtle.compareTo(t) == true
  22.    then s = 2
  23.    return s
  24.    else turtle.select(3)
  25.   end
  26.   if turtle.compareTo(t) == true
  27.    then s = 3
  28.    return s
  29.    else turtle.select(4)
  30.   end
  31.   if turtle.compareTo(t) == true
  32.    then s = 4
  33.    return s
  34.    else turtle.select(5)
  35.   end
  36.   if turtle.compareTo(t) == true
  37.    then s = 5
  38.    return s
  39.    else turtle.select(6)
  40.   end
  41.   if turtle.compareTo(t) == true
  42.    then s = 6
  43.    return s
  44.    else turtle.select(7)
  45.   end
  46.   if turtle.compareTo(t) == true
  47.    then s = 7
  48.    return s
  49.    else turtle.select(8)
  50.   end
  51.   if turtle.compareTo(t) == true
  52.    then s = 8
  53.    return s
  54.    else turtle.select(9)
  55.   end
  56.   if turtle.compareTo(t) == true
  57.    then s = 9
  58.    return s
  59.    else turtle.select(10)
  60.   end
  61.   if turtle.compareTo(t) == true
  62.    then s = 10
  63.    return s
  64.    else turtle.select(11)
  65.   end
  66.   if turtle.compareTo(t) == true
  67.    then s = 11
  68.    return s
  69.    else turtle.select(12)
  70.   end
  71.   if turtle.compareTo(t)
  72.    then s = 12
  73.    return s
  74.    else print "no valid materials"
  75.   end
  76. end
  77. --this function allows for the choosing
  78. -- of the dimensions of the building
  79. function getDim(x,y,z)
  80. print "please enter desired length:"
  81.  l = io.read()
  82.  print "please enter desired width:"
  83.  w = io.read()
  84.  print "please enter desired height:"
  85.  h = io.read()
  86.  print (l..w..h)
  87.  return l, w, h
  88.  end
  89. --floor building function
  90. function floor(x,t,c )
  91. t = 13
  92. comp(t,c)
  93. c = s
  94. for i = 1, x do
  95.  turtle.digDown()
  96.  turtle.placeDown()
  97.  if turtle.getItemCount(c) == 0
  98.   then comp(t,c)
  99.   c = s
  100.  end
  101.  forward()
  102. end
  103. for i = 1, x do
  104.  turtle.back()
  105.  end
  106.  turtle.turnRight()
  107.  forward()
  108.  turtle.turnLeft()
  109.  fuel(c)
  110. end
  111. --wall building function
  112. function walls(x,y,t,c)
  113. t = 14
  114. comp(t,c)
  115. c = s
  116. turtle.placeDown()
  117. for k = 1 , x-1
  118.  do forward()
  119.   turtle.placeDown()
  120.   if turtle.getItemCount(c) == 0
  121.    then comp(t,c)
  122.    c = s
  123.   end
  124.   fuel(c)
  125.  end
  126.  turtle.turnRight()
  127.  forward()
  128.  for i = 1 , y-2  
  129.   do if turtle.getItemCount(c) == 0
  130.   then comp(t,c)
  131.   c = s
  132.   end
  133.   turtle.placeDown()
  134.   forward()
  135.  end
  136.  fuel(c)
  137.  turtle.turnRight()
  138. end
  139.  
  140. -- this is the function to make the roof
  141. function roof(x,y,t,c)
  142.  t = 15
  143.  comp(t,c)
  144.  c = s
  145.  turtle.forward()
  146.  turtle.turnRight()
  147.  turtle.forward()
  148.  turtle.down()
  149.  for i = 1 , x-2
  150.   do for j = 1, y-2
  151.    do if turtle.getItemCount(c) == 0
  152.         then
  153.         comp(t,c)
  154.         c = s
  155.         end
  156.        turtle.placeDown()
  157.        turtle.forward()
  158.    end
  159.     for k= 1, y-2
  160.      do turtle.back()
  161.     end
  162.     turtle.turnLeft()
  163.     forward()
  164.     turtle.turnRight()
  165.   end    
  166. end
  167.  
  168. -- refueling function
  169. function fuel(c)
  170. if turtle.getFuelLevel() <=500
  171.  then turtle.select(16)
  172.  turtle.refuel(2)
  173.  print(turtle.getFuelLevel())
  174.  turtle.select(c)
  175.  end
  176. end
  177. -- functions included to reduce lines of code
  178. -- and to allow for a stuck check
  179. function forward()
  180.  if turtle.forward() ~= true
  181.   then turtle.dig() turtle.forward()
  182.  end
  183. end
  184. function up()
  185.  if turtle.up() ~= true
  186.   then turtle.digup()
  187.      turtle.up()
  188.      fuel(c)
  189.   else fuel(c)
  190.  end
  191. end
  192.  
  193. -- main program
  194. local x, y, z, t, c
  195. instructions()
  196. --sleep(7)
  197. getDim()
  198. x = l
  199. y = w
  200. z = h
  201. print (x..y..z)  
  202. for j= 1, y do
  203.  floor(x,t,c)
  204. end
  205. turtle.turnLeft()
  206. for j= 1, y do
  207. forward()
  208. end
  209. turtle.turnRight()
  210. up()
  211. for l= 1 , z
  212.  do
  213.    for m = 1 , 2
  214.     do
  215.   walls(x,y,t,c)
  216.  end
  217.  up()
  218. end
  219. roof(x,y,t,c)
  220.  turtle.turnRight()
  221.  for i = 1 , x
  222.  forward()
  223.  end
  224.  turtle.turnRight()
  225.  forward()
  226.  turtle.turnLeft()
  227.  for j = 1 . z
  228.  do turtle.down
  229.  end
Advertisement
Add Comment
Please, Sign In to add comment