Advertisement
masa-

CC Turtle: Testing stuff

Apr 6th, 2013
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.70 KB | None | 0 0
  1.  
  2.  
  3.  
  4. -- Get the number of empty slots in inventory
  5. function getInvNumEmptySlots()
  6.     local slots = 0
  7.  
  8.     -- FIXME TODO: check for auto-refuel enabled
  9.     local lastSlot = 16
  10.     for i = 1, lastSlot do
  11.         if turtle.getItemCount(i) == 0 then
  12.             slots = slots + 1
  13.         end
  14.     end
  15.  
  16.     return slots
  17. end
  18.  
  19.  
  20. -- Get the number of items in inventory
  21. function getInvNumItems()
  22.     local num = 0
  23.  
  24.     -- FIXME TODO: check for auto-refuel enabled
  25.     local lastSlot = 16
  26.     for i = 1, lastSlot do
  27.         num = num + turtle.getItemCount(i)
  28.     end
  29.  
  30.     return num
  31. end
  32.  
  33.  
  34. -- Get the number of items that can be added into inventory
  35. function getInvFreeSpace()
  36.     local fs = 0
  37.  
  38.     -- FIXME TODO: check for auto-refuel enabled
  39.     local lastSlot = 16
  40.     for i = 1, lastSlot do
  41.         fs = fs + turtle.getItemSpace(i)
  42.     end
  43.  
  44.     return fs
  45. end
  46.  
  47.  
  48. -- Loop through the inventory
  49. function invLoop()
  50.  
  51.     -- FIXME TODO: check for auto-refuel enabled
  52.     local lastSlot = 16
  53.     for i = 1, lastSlot do
  54.         turtle.select(i)
  55.     end
  56.  
  57.     return true
  58. end
  59.  
  60.  
  61. -- Compare the block to each slot in inventory
  62. function compareToInv()
  63.  
  64.     -- FIXME TODO: check for auto-refuel enabled
  65.     local lastSlot = 16
  66.     for i = 1, lastSlot do
  67.         turtle.select(i)
  68.         if turtle.compare() == true then
  69.             print("Block matches!")
  70.             break
  71.         end
  72.     end
  73.  
  74.     return true
  75. end
  76.  
  77. print("Before...")
  78. print("getInvNumEmptySlots(): " .. getInvNumEmptySlots() )
  79. print("After...")
  80.  
  81. print("Before...")
  82. print("getInvFreeSpace(): " .. getInvFreeSpace() )
  83. print("After...")
  84.  
  85. print("Before...")
  86. print("getInvNumItems(): " .. getInvNumItems() )
  87. print("After...")
  88.  
  89. print("Before...")
  90. invLoop()
  91. print("invLoop()")
  92. print("After...")
  93.  
  94. print("Before...")
  95. compareToInv()
  96. print("compareToInv()")
  97. print("After...")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement