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

How to separate multiple components of the same name in code?

Question

I have two Flux Gates (Draconic Evolution) in a setup, but the problem is that I don't know how to separate the two in code. If there was only one I could do something like "local gate = component.flux_gate". It would be easier to write the code if I could give them names separately such as "gate_in" and "gate_out". How do I do this?

Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

To start, components dont really have 'names'. Names aren't unique and we end up with the issue you've mentioned. Components have 'types' and 'addresses'. When using the component library fields like component.flux_gate what is actually happening is the component library is looking up the 'primary' component, really this is just the first component of that type to be found.

print( component.flux_gate == component.getPrimary('flux_gate') ) -- # this should print 'true'

To find individual components of a certain type you can call component.list

local flux_gates = {}

for address in component.list('flux_gate') do
  local gate = component.proxy(address)
  table.insert(flux_gates, gate)
end

-- or

local gate_iter = component.list('flux_gate')
local fg1, fg2 = component.proxy(gate_iter()), component.proxy(gate_iter())

 

Link to post
Share on other sites
  • 0

I assume the Flux Points are connected using an adapter, so you can use the Analyzer on said adapters while holding Ctrl to copy each address into the clipboard and then paste it into the script using the following code to get each instance:

local component = require("component")

local fluxPoint1Address = "<ADDRESS 1 GOES HERE>"
local fluxPoint2Address = "<ADDRESS 2 GOES HERE>"

local fluxPoint1 = component.get(fluxPoint1Address)
local fluxPoint2 = component.get(fluxPoint2Address)

-- Do whatever with the flux points

You don't need the address variables, I just place them with other settings / addresses / etc at the top of the file so they are easy to edit if needed (and I don't have to search for them throughout the file).

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.