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

Accessing more than one of the same type of component

Question

How can I access multiple instances of the same component? I'm making a control and monitoring system for Big Reactors and I need to be able to monitor the reactor and 8+ turbines at the same time. How can I do this?

Share this post


Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 0

you can use the component.proxy() function by passing the UUID of the individual component you want to control, you can then use it like a normal component

Share this post


Link to post
Share on other sites
  • 0

This is really late, but for any future visitors, here's what I do:

(Basically just make a lua file that has variables containing the addresses, the variables are your custom names).

Steps 1-3 are kinda optional, they're just meant to make it easier to copy and paste the addresses.

1. Make a small script to get all the device names and output them to a text file, let's call it "get_addresses.lua"

local component = require("component")
local file = io.open("component_addresses.txt", "w")

for a,b in pairs(component.list()) do
  line = a .. " - " .. b .. "\n"
  file:write(line)
end

io.close(file)

Execute the script and you will now have a text file (component_addresses.txt) that contains the address and device name. You can use "cat component_addresses.txt" from command line to view them.

2. Export the text file so that you can highlight and copy+paste the addresses instead of having to type them out. This requires an internet card in your computer. From the computer's command line run:

pastebin put component_addresses.txt

3. The computer will upload the text file and output the pastebin URL eg. "pastebin.com/XXXXXX". Go to the URL (you're gonna have to type it, but it's pretty short)

4. Here is where we give our devices names, let's make another lua file called "device_name.lua". In this example I will use two redstone components, one controlling a piston door another controlling a drawbridge. You can use your pastebin file to copy and paste the addresses (if you don't already know, you can press the insert key on your keyboard to paste in OpenComputers):

local address_list = 
{
  piston_door = "8e8d0032-c32c-4b3d-a6a2-acc9d1bb1996",
  drawbridge = "4c4dcfb2-1a61-4158-91f2-7da6d53a1b0b",
}

return address_list

Obviously, you'll just need to replace the addresses with your respective component addresses.

5. Now you have a file containing custom names with their corresponding address. To use the file in your script simply use:

local component = requires("component")
local device = requires("device_name")

local piston_door = component.proxy(device.piston_door)
local drawbridge = component.proxy(device.drawbridge)

-- you can now use your usual calls, the door and drawbridge are redstone components, which can be used for example:
piston_door.setOutput(1, 15)
drawbridge.setOutput(2, 15)

 

It's a longish process, but you're only going to need to do this once, and again when you add more components that you want to give custom names. The annoying part is identifying which address belongs to which specific component, the rest is pretty simple.

Share this post


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.