This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
component:component_access [2015/01/14 23:40] 127.0.0.1 external edit |
component:component_access [2018/11/27 14:59] (current) krakodeel [Addresses] |
||
---|---|---|---|
Line 5: | Line 5: | ||
Addresses | Addresses | ||
--------- | --------- | ||
- | Components all have an address. This address is a UUID, a unique identifier. In most cases it is OK to abbreviate these addresses. For example to get the full address from an abbreviated one you can use `component.get`. To get the address of any block in particular, you can use the [[:analyzer|Analyzer]] by holding the control key while right clicking the block. | + | Components all have an address. This address is a UUID, a unique identifier. In most cases it is OK to abbreviate these addresses. For example to get the full address from an abbreviated one you can use `component.get`. To get the address of any block in particular, you can use the [[item:analyzer|Analyzer]] by holding the control key while right clicking the block. |
To get a list of all components attached to your computer you can do this: | To get a list of all components attached to your computer you can do this: | ||
Line 19: | Line 19: | ||
Note that item components will usually keep their address even when removed from a computer. So when removing a hard drive and inserting it back in, it will have the same address as before. This is *not* the case for block components, they will always get a new address after being broken and placed again. | Note that item components will usually keep their address even when removed from a computer. So when removing a hard drive and inserting it back in, it will have the same address as before. This is *not* the case for block components, they will always get a new address after being broken and placed again. | ||
+ | |||
+ | Optionally you can filter components list like this: | ||
+ | |||
+ | This code will add every component which name contains "adar" such as computronics radar or warpDrive radar to the local radars table | ||
+ | ```lua | ||
+ | local component = require("component") | ||
+ | local radars = {} | ||
+ | for address, name in component.list("adar", false) do | ||
+ | table.insert(radars, component.proxy(address)) | ||
+ | end | ||
+ | ``` | ||
+ | |||
+ | This code will add all connected warpDrive radars only to the local radars table | ||
+ | ```lua | ||
+ | local component = require("component") | ||
+ | local radars = {} | ||
+ | for address, name in component.list("warpdriveRadar", true) do | ||
+ | table.insert(radars, component.proxy(address)) | ||
+ | end | ||
+ | ``` | ||
Primary Components | Primary Components |