Added new scripts and sorted things
This commit is contained in:
		
							
								
								
									
										35
									
								
								Modules/hare.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								Modules/hare.lua
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
--[[Function Module program by Al Sweigart
 | 
			
		||||
Provides useful utility functions.]]
 | 
			
		||||
 | 
			
		||||
-- selectItem() selects the inventory
 | 
			
		||||
-- slot with the named item, returns
 | 
			
		||||
-- true if found and false if not
 | 
			
		||||
function selectItem(name)
 | 
			
		||||
-- check all inventory slots
 | 
			
		||||
 local item
 | 
			
		||||
  for slot = 1, 16 do
 | 
			
		||||
    item = turtle.getItemDetail(slot)
 | 
			
		||||
    if item ~= nil and item['name'] == name then
 | 
			
		||||
      turtle.select(slot)
 | 
			
		||||
      return true
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  return false  -- couldn't find item
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
-- selectEmptySlot() selects inventory
 | 
			
		||||
-- slot that is empty, returns true if
 | 
			
		||||
-- found, false if no empty spaces
 | 
			
		||||
function selectEmptySlot()
 | 
			
		||||
 | 
			
		||||
  -- loop through all slots
 | 
			
		||||
  for slot = 1, 16 do  
 | 
			
		||||
    if turtle.getItemCount(slot) == 0 then
 | 
			
		||||
      turtle.select(slot)
 | 
			
		||||
      return true
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
  return false -- couldn't find empty space
 | 
			
		||||
end
 | 
			
		||||
		Reference in New Issue
	
	Block a user