-
Notifications
You must be signed in to change notification settings - Fork 435
Signals
For those that don't like images: the wiki has moved to a new place, http://ocdoc.cil.li/.
This wiki will no longer be updated.
Signals are messages sent to a computer from some external source and can be used for many purposes. They always have at least a name, and may have any number of (simple) parameters. Note that computers may also queue signals on themselves.
Signals can be consumed using computer.pullSignal() or its preferred wrapper, event.pull(). The latter is preferred because unwanted signals and the requested signal itself are also distributed as events, which is used by a couple of system functions, such as primary component tracking.
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:
local event = require("event")
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
-
component_added(address: string, componentType: string)
This signal is queued by the computer or 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
orgpu
).
Note: do not use this directly when possible, but usecomponent_available
instead, which is queued by the component library when a primary component was added / the primary component changed. -
component_removed(address: string, componentType: string)
This signal is queued by the computer or 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
orgpu
).
Note: do not use this directly when possible, but usecomponent_unavailable
instead, which is queued by the component library when a primary component is removed. -
component_available(componentType: string)
This signal is queued by the component library when a primary component was added / the primary component changed. It is generally preferred to use this overcomponent_added
, to avoid conflicts with the component library. -
component_unavailable(componentType: string)
This signal is queued by the component library when a primary component is removed. It is generally preferred to use this overcomponent_removed
, to avoid conflicts with the component library. -
term_available()
This signal is queued by the term library when both a GPU and 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 when either the primary GPU or screen becomes unavailable in a computer. This is useful to determine when it becomes impossible to print text to an attached screen.
-
screen_resize(screenAddress: string, newWidth: number, newHeight: number)
This signal is queued by screens when their resolution changes, for example because it is manually set via the GPU. The address is the address of the screen the queued the signal. -
touch(screenAddress: string, x: number, y: number, button: number, playerName: string)
This signal is queued by screens of tier two and tier three when they are clicked. This includes left clicks in the GUI (i.e. when a keyboard is attached) or when right-clicking/activating them in the world directly (i.e. when no keyboard is attached). The address is the address of the screen the queued the signal. The x and y coordinates are in "letters" (meaning they map directly toterm.setCursor
orgpu.set
, for example). The player name is the user name of the player that triggered the event.
Note on the player name: I'll probably add an option to disable this argument in the future, for those who think it's too... unrealistic. It's just quite handy for multi-user programs, so I left it in for now.
Important: this signal is checked, i.e. it is only queued on a computer if the player that caused it is registered as a user on the computer (or there are no users registered on the computer). -
drag(screenAddress: string, x: number, y: number, button: number, playerName: string)
This signal is almost equivalent to thetouch
signal. The only difference is the implicit meaning: when this signal is fired, it "belongs" to atouch
signal that was fired earlier. This can only be triggered by dragging in the GUI. -
drop(screenAddress: string, x: number, y: number, button: number, playerName: string)
This signal is only triggered if adrag
event was triggered first. It is fired when the player releases the mouse button, so it's basically a conditional mouse-up event (with the condition being that the mouse moved while the button was held). -
scroll(screenAddress: string, x: number, y: number, direction: number, playerName: string)
This signal is queued by screens of tier two and tier three when the player uses the mouse wheel in the GUI. The x and y coordinates are the cursor location when the scroll occurred and are, like thetouch
signal, in "letters". Thedirection
indicates which way to scroll, where a positive value usually means "up", whereas a negative value means "down". Note that this may differ based on the client's operating system and/or driver configuration. The player name is the user name of the player that triggered the event.
The same considerations apply to the player name parameter as intouch
. -
walk(screenAddress: string, x: number, y: number[, playerName: string])
This signal is queued by screens of tier two and tier three when a player or other entity walks on them. The address is the address of the screen the queued the signal. The x and y coordinates are the coordinates of the sub-block of the multi-block screen that queued the event. Use gpu.getSize() to figure out which area of the display that actually represents.
Unlike clicks, this can be triggered for regions of the screen where nothing is displayed based on the current resolution, so keep that in mind.
The same considerations apply to the player name parameter as intouch
.
-
key_down(keyboardAddress: string, char: number, code: number, playerName: string)
This signal is queued by keyboards when a user inputs something on the screen it's attached to, more specifically when the user presses a key. This event may be repeated if the user keeps pressing the key.
Important: this signal is checked, i.e. it is only queued on a computer if the player that caused it is registered as a user on the computer (or there are no users registered on the computer). -
key_up(keyboardAddress: string, char: number, code: number, playerName: string)
This signal is queued by keyboards when a user inputs something on the screen it's attached to, more specifically when the user releases a key.
Note that although most cases where a player can be "removed" from a screen without releasing the key before-hand should be handled (I think) there may still be cases where this fails. Meaning this feature is more or less in an... observation stage, and may be removed at a later point if it proves infeasible.
Important: this signal is checked, i.e. it is only queued on a computer if the player that caused it is registered as a user on the computer (or there are no users registered on the computer). -
clipboard(keyboardAddress: string, value: string, playerName: string)
This signal is queued by keyboards when a user pastes text from the clipboard (Shift+Ins or middle mouse button). Note that the maximum length of the text that can be pasted is limited (can be changed in the config). Important: this signal is checked, i.e. it is only queued on a computer if the player that caused it is registered as a user on the computer (or there are no users registered on the computer).
-
redstone_changed(address: string, side: number)
This signal is queued by redstone components when an incoming signal changes. The address is either that of the Redstone I/O block or that of the computer with the redstone card that generated the signal. The side is one of the sides constants and indicates on which side the signal changed. This is relative to the container of the component, so for computers and robots this depends on which way they are facing. For Redstone I/O blocks this is always the absolute side.
-
modem_message(receiverAddress: string, senderAddress: string, port: number, distance: number, ...)
This signal is queued by network cards (including wireless ones) when they receive a message on an open port. The first address is the address of the network card that received the message, the second the address from where the message was sent. Note that the sender address may differ from the card that originally sent the message when it passed through one or more routers. The port is the port on which the message was received. This distance is the distance only set when receiving wireless network messages, in which case it is the distance to the wireless network card that sent the message. For normal network cards the distance will always be zero. All further parameters are user defined and correspond to what the sender specified in modem.send() ormodem.broadcast()
as the message's payload.
-
inventory_changed(slot: number)
This signal is queued by robots when their inventory changes. Note that this only includes changes to the kind of item stored in a slot. For example, increasing or decreasing the size of an already present stack does not trigger this signal. However, swapping one item with another (say, torches with sticks) by hand will actually trigger two signals: one for the removal of the torches, one for putting the sticks into the temporarily empty slot. Swapping items using robot.transferTo() will even trigger four signals - the same thing, but for the two slots involved in the swap.
Also, this only fires for the actually addressable inventory of the robot, i.e. it does not trigger for changes in equipment (tool, card, upgrade).
-
bus_message(protocolId: number, senderAddress: number, targetAddress: number, data: table, metadata: table)
-
protocolId
is the protocol version that was used. -
senderAddress
is the address of the device sending the message. -
targetAddress
is the address of the device that the messages was intended for (-1 for network broadcasts). -
data
is a table of the data that was sent. -
metadata
is a table of data that are unique to the device that send the address.
-
Important: This component has moved to the OpenComponents addon.
-
carriage_moved(success: boolean[, reason:string[, x:number, y: number, z: number]])
This signal is queued by the carriage component after a move or simulate command was issued. Thesuccess
parameter indicates whether the move or simulation was successful, i.e. whether the carriage could be moved. If the move failed,reason
is the error message. Depending on the error message, (x
,y
,z
) is the world coordinate of the block that caused the move to fail.