mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-14 09:46:53 -04:00
Updated ComponentAccess (markdown)
parent
642973edce
commit
a493caaa64
@ -2,7 +2,6 @@ This page describes how to get access to a [[component's API|Components]] from L
|
||||
|
||||
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|Items#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:
|
||||
@ -20,7 +19,6 @@ Note that item components will usually keep their address even when removed from
|
||||
|
||||
Primary Components
|
||||
------------------
|
||||
|
||||
The [[component API|API/Component]] keeps track of one component of each type as a "primary" component. If there are multiple components of the same type, which one will be the primary component is random. You can access the primary component of a specific type via `component.xxx`, where `xxx` is the type. For example:
|
||||
```
|
||||
lua> component.gpu.address
|
||||
@ -33,7 +31,6 @@ This system is in mainly place to allow the OS to pick the screen to initially o
|
||||
|
||||
Proxies
|
||||
-------
|
||||
|
||||
So now that we know how to get the address of components, let's see how we can interact with them. There are two ways to go about this. One is to call `component.invoke(address, method, ...)`. For example:
|
||||
```lua
|
||||
component.invoke(modemAddress, "broadcast", port, data)
|
||||
@ -55,5 +52,8 @@ Note that each primary component you access via `component.getPrimary` or `compo
|
||||
|
||||
Direct Calls
|
||||
------------
|
||||
Using proxies is generally preferable to `component.invoke`, since proxies can perform "direct calls", if supported by the component; `component.invoke` doesn't. Direct calls are performed in the computer's worker thread, meaning they will return instantly. Normal calls are delegated to the main server thread, to avoid race conditions and other threading issues, which also means that normal calls will take at least one tick (i.e. 50 ms). Just to be clear: this only applies to component APIs.
|
||||
|
||||
Using proxies is generally preferable to `component.invoke`, since proxies can perform "direct calls", if supported by the component; `component.invoke` doesn't. Direct calls are performed in the computer's worker thread, meaning they will return instantly. Normal calls are delegated to the main server thread, to avoid race conditions and other threading issues, which also means that normal calls will take at least one tick (i.e. 50 ms). Just to be clear: this only applies to component APIs.
|
||||
Signals
|
||||
-------
|
||||
An important part of interacting with components are [[signals|Signals]]. These can be queued by components to notify computers of external changes and events. For example, user input is forwarded to computers via signals. Computers can also queue their own signals, which can be useful for code-reuse, or just notifying other parts of your code asynchronously.
|
Loading…
x
Reference in New Issue
Block a user