Skip to content

Signals

Florian Nücke edited this page Dec 12, 2013 · 14 revisions

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()|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().

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.
  • click(screenAddress: string, x: number, y: 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 to term.setCursor or gpu.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).
  • 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()|Component/GPU]] 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 in click.
  • 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|API/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()|Component/Modem]] or modem.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()|API/Robot]] 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).
Clone this wiki locally