Advertisement
asweigart

Hare Module ver 1

Aug 24th, 2017
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.83 KB | None | 0 0
  1. --[[ "Hare" utility library by Al Sweigart
  2. Provides useful utility functions. ]]
  3.  
  4. -- selectItem() selects the inventory
  5. -- slot with the named item, returns
  6. -- true if found and false if not
  7. function selectItem(name)
  8.   -- check all inventory slots
  9.   local item
  10.   for slot = 1, 16 do
  11.     item = turtle.getItemDetail(slot)
  12.     if item ~= nil and item['name'] == name then
  13.       turtle.select(slot)
  14.       return true
  15.     end
  16.   end
  17.  
  18.   return false  -- couldn't find item
  19. end
  20.  
  21.  
  22. -- selectEmptySlot() selects inventory
  23. -- slot that is empty, returns true if
  24. -- found, false if no empty spaces
  25. function selectEmptySlot()
  26.  
  27.   -- loop through all slots
  28.   for slot = 1, 16 do
  29.     if turtle.getItemCount(slot) == 0 then
  30.       turtle.select(slot)
  31.       return true
  32.     end
  33.   end
  34.   return false -- couldn't find empty space
  35. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement