RolandLundvall

Crafty Turtle test 1

Apr 19th, 2014
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.14 KB | None | 0 0
  1. --CraftyTurtle
  2.  
  3. function empty()
  4.  
  5. print ("Program terminated, emptying slots.")
  6.  
  7.         for i = 1, 12, 1 do
  8.                 turtle.select(i)
  9.                 turtle.dropDown()
  10.         end --for end
  11.  
  12. turtle.select(16)
  13. turtle.dropUp()
  14. print ("Turtle is empty. Thanx for using CraftyTurtle. See you soon.")
  15. b = b+1
  16.  
  17. end --function end
  18.  
  19.  
  20. function fill()          --fill inventory with contents
  21.  
  22. print("starting function fill")
  23.  
  24. print ("Creating table.")
  25.  
  26. slotTable = {"y","y","y","n","n","y","n","n","y","y","y","c"}            --create table of the slots to be used and not in the turtles inventory. When it comes to "c" (close) program part should terminate.
  27.  
  28. print ("Table created")
  29. print("Testing table")
  30.  
  31. for i=1, 12, 1 do
  32. print(slotTable[i])
  33. print("This was slotTable")
  34. end
  35.  
  36. local x = 1
  37. print("after local x")
  38.         while x == 1 do
  39.         print("Inside while x == 1")
  40.                 while turtle.suckDown do                                                                --as long as there is materials in chest below
  41.                 print("Inside while suckDown")
  42.                         for i = 1, 12, 1 do             --go through slots 1 to 12
  43.                         print(i)
  44.                         turtle.select(i)
  45.                        
  46.                        
  47.                                 if slotTable[i] == y then               --look in tablearray
  48.                                 turtle.suckDown()                                                               --fill the slot
  49.  
  50.  
  51.                                 elseif slotTable[i] == n then            --if this returns n it means slot should stay empty
  52.                                 print ("This slot is not in use.")
  53.  
  54.                                 elseif slotTable[i] == c then            --if this returns c the function shall close
  55.                                 print("All slots full!")
  56.                                 x = x+1                                                                                 --this closes the function
  57.                                 else
  58.                                 end  --if-elseif-end
  59.  
  60.  
  61.                         end --for-loop end
  62.                 end --while end
  63.         end  --while end
  64.  
  65. end --function end
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74. function make()
  75. print("starting function make")
  76.  
  77. local x = 1
  78.  
  79.         while x == 1 do
  80.  
  81.                 while turtle.dropUp() == true do                 --if there is space left in chest
  82.                         turtle.select(16)                        --select slot 16
  83.  
  84.                                 if turtle.getItemCount() == 0 then               --if slot 16 in empty
  85.                                         turtle.craft()                                                   --make things with the materials in the slots filled
  86.                                         turtle.dropUp()                                          --put things in chest above
  87.                                         print ("Tillverkade en stack")
  88.  
  89.                                 elseif turtle.dropUp ~= false then                                       --if chest above has space left
  90.                                         turtle.dropUp()                                  --empty slot 16 to chest
  91.                                         turtle.craft()                                           --make the things
  92.                                         turtle.dropUp()                                  --put things in chest above
  93.                                         print ("Tillverkade en stack")
  94.                                                                                          --terminates the function
  95.                                 else
  96.  
  97.                                         print ("Målkista är full!!!!")           --if chest is full it will be prompted. If the chest becomes full during work (as in not full before function starts), I assume both prints would be done (this and the one below)?
  98.                                         a = 3
  99.  
  100.                                 end --if-elseif end
  101.                 end   --while end      
  102.  
  103.                 print ("Målkistan är full!")    --if turtle.dropUp returns false chest is full and player will be prompted this
  104.                 x = x+1
  105.  
  106.         end --while end
  107. end --function end
  108.  
  109.  
  110.  
  111. function wait()
  112.  
  113. print("starting wait")
  114.  
  115. local x = 1
  116.  
  117.         while x == 1 do
  118.  
  119.                 if a == 2 then
  120.  
  121.                         while not turtle.suckDown() do                   --while there are no materials in chest
  122.                         print ("Väntar på material.....")                --print waiting for mats..
  123.  
  124.  
  125.                         end  --while end
  126.  
  127.                 elseif a == 3 then
  128.  
  129.                         while not turtle.dropUp() do    --I assume this means that as long as chest above is full 'turtle.dropUp' will return false?
  130.                         print ("Chest full. Waiting for user to empty it.")
  131.  
  132.                         end --while end
  133.  
  134.                 else
  135.                 print ("a was neither 2 nor 3...")
  136.                 end --if-elseif end
  137.         end --while end
  138. end --function end
  139.  
  140. --main program
  141.  
  142. print ("Welcome to CraftyTurtle.")
  143. print("Place a chest under and above the turtle.")
  144. print("This program will terminate when chest below is empty.")
  145.  
  146. a = 1
  147. b = 1
  148. d= 1
  149.  
  150.  
  151.  
  152. while b == 1 do
  153.         while d == 1 do
  154.                 while turtle.suckDown() do                               --Would this be the same as 'while turtle.suckDown == true do'?
  155.                         print("inside first while loop")                                                        
  156.                                 while turtle.dropUp() do                 --while there is materials in chest below And if there is space in chest on top
  157.                                 print ("ready to work.")
  158.                                         fill()  
  159.                                         make()
  160.                                 end --while end
  161.                         print ("Top chest full. Terminating")                  
  162.                 end --while end
  163.                 d = d +1
  164.         end --while d end
  165. empty()
  166. end --while b end
Advertisement
Add Comment
Please, Sign In to add comment