mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-08-04 03:27:19 -04:00
Updated Signals (markdown)
parent
bb116c1fd4
commit
919442afb2
27
Signals.md
27
Signals.md
@ -2,7 +2,32 @@ Signals are messages sent to a computer from some external source and can be use
|
|||||||
|
|
||||||
Signals can be consumed using `[[computer.pullSignal()|API/Computer]]` or its preferred wrapper, `[[event.pull()|API/Event]]`.
|
Signals can be consumed using `[[computer.pullSignal()|API/Computer]]` or its preferred wrapper, `[[event.pull()|API/Event]]`.
|
||||||
|
|
||||||
The following lists all signals triggered by components and the built-in libraries. They are listed in the following format: `name(arg: type, ...)`, meaning you would pull them like `local name, arg, ... = event.pull()`.
|
The following lists all signals triggered by components and the built-in libraries. They are listed in the following format: `name(arg: type, ...)`, meaning you would pull them like `local name, arg, ... = event.pull()`. For example, to pull a modem message:
|
||||||
|
```lua
|
||||||
|
local _, localNetworkCard, remoteAddress, port, distance, payload = event.pull("modem_message")
|
||||||
|
print("Received data '" .. tostring(payload) .. "' from address " .. remoteAddress ..
|
||||||
|
" on network card " .. localNetworkCard .. " on port " .. port .. ".")
|
||||||
|
if distance > 0 then
|
||||||
|
print("Message was sent from " .. distance .. " blocks away.")
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
Computer
|
||||||
|
--------
|
||||||
|
- `component_added(address: string, componentType: string)`
|
||||||
|
This signal is queued by the [[computer|Blocks#basic-case]] or [[robot|Blocks#robot]] when a new component is attached to it. The address is the address of the added component, `componentType` is the type of the component (e.g. `redstone` or `gpu`).
|
||||||
|
Note: do not use this directly when possible, but use `component_available` instead, which is queued by the [[component library|API/Component]] when a *primary* component was added / the primary component changed.
|
||||||
|
- `component_removed(address: string, componentType: string)`
|
||||||
|
This signal is queued by the [[computer|Blocks#basic-case]] or [[robot|Blocks#robot]] when a component is removed from it. The address is the address of the removed component, `componentType` is the type of the component (e.g. `redstone` or `gpu`).
|
||||||
|
Note: do not use this directly when possible, but use `component_unavailable` instead, which is queued by the [[component library|API/Component]] when a *primary* component is removed.
|
||||||
|
- `component_available(componentType: string)`
|
||||||
|
This signal is queued by the [[component library|API/Component]] when a *primary* component was added / the primary component changed. It is generally preferred to use this over `component_added`, to avoid conflicts with the component library.
|
||||||
|
- `component_unavailable(componentType: string)`
|
||||||
|
This signal is queued by the [[component library|API/Component]] when a *primary* component is removed. It is generally preferred to use this over `component_removed`, to avoid conflicts with the component library.
|
||||||
|
- `term_available()`
|
||||||
|
This signal is queued by the [[term library|API/Term]] when both a [[GPU|Items#basic-graphics-card]] *and* [[screen|Blocks#basic-screen]] become available in a computer. This is useful to determine whether it is now possible to print text to an attached screen.
|
||||||
|
- `term_unavailable()`
|
||||||
|
This signal is queued by the [[term library|API/Term]] when either the primary [[GPU|Items#basic-graphics-card]] or [[screen|Blocks#basic-screen]] becomes unavailable in a computer. This is useful to determine when it becomes impossible to print text to an attached screen.
|
||||||
|
|
||||||
Screen
|
Screen
|
||||||
------
|
------
|
||||||
|
Loading…
x
Reference in New Issue
Block a user