Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
Trellinane

How to identify which side is connected to the computer

Question

Hello,

I am looking for a way to identify which side of an external block is connected to the computer network.  For instance if I had a chest connected to an inventory and wanted to be able to use an inventory_controller upgrade to inspect contents I would have to know which side to access in the methods.  What if a user hooked the chest to a different side than the way I wrote the code.  In other words, have the program search and determine which side to utilize in the program.  This is my first attempt with open computers so I may be missing something really obvious.  Thanks.

 

 

Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0
local function findInvs(ic) -- # ic: inventory_controller proxy
  local invs = {}
  
  -- # Loop over all sides for an inventory name.
  for side = 0, 5 do
  	local name = ic.getInventoryName(side)
    -- # If an inventory name is present then store the name/type and the side:number
    if name then table.insert(invs, {name = name, side = side}) end
  end
  
  return invs
end

Example:

local component = require 'component'
local sides = require 'sides'

local ic = component.inventory_controller
local inventories = findInvs(ic)

for i, inv in ipairs(inventories) do
  local side, size = sides[inv.side], ic.getInventorySize(inv.side)
  print("inventory at side: '" .. side .. "' has " .. tostring(size) .. " slots")
end

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.