Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Variables
- local Connected_Inventories = {}
- local Inventory = {}
- local Slot_Count = 16
- --Functions
- local function readInventory(InventoryIndex,InventoryID)
- --make a list of every item,its count,and slot number.
- local ItemInfo_List = {}
- for i = 1,Slot_Count do
- local ItemInfo = turtle.getItemDetail(i)
- if ItemInfo then
- local Item_Info = {ItemInfo[1],ItemInfo[2],i}
- table.insert(ItemInfo_List,Item_Info)
- end
- end
- return ItemInfo_List
- end
- local function addItemToInvList(ItemInfos)
- --Add item and count to the general Inventory list.
- table.insert(Inventory,ItemInfos)
- end
- local function moveInfo(Inventory_List)
- for Item_Index,Item_Information in pairs(Inventory_List) do
- addItemToInvList(Item_Information)
- end
- end
- local function takeInventory()
- for Inventory_Index,Inventory_ID in pairs(Connected_Inventories) do
- local InvList = readInventory(Inventory_Index,Inventory_ID)
- --for every item in the readInventory lists, add its name and its count to the general Inventory list.
- moveInfo(InvList)
- end
- return Inventory
- end
- local function printInventory()
- takeInventory()
- print("Inventory: ")
- for ItemIndex,ItemInformation in pairs(Inventory) do
- print(ItemInformation[1]..";"..ItemInformation[2])
- end
- end
- --Program starts
- for Peripheral_Index,Peripheral_ID in pairs(peripheral.getNames()) do
- local Current_Peripheral = peripheral.wrap(Peripheral_ID)
- local Peripheral_Name,Peripheral_Type = peripheral.getType(Current_Peripheral)
- if Peripheral_Type == "inventory" then
- table.insert(Connected_Inventories,Current_Peripheral)
- end
- end
- printInventory()
Advertisement
Add Comment
Please, Sign In to add comment