Events

How to listen to events

You can listen to any event by calling a function os.pullEvent(), which will block execution until some event occurs. You can specify a single event name if you are not interested in other events os.pullEvent("name_of_the_event").

Wrapping the os.pullEvent() call to {} allows taking all the event’s return values as a single table.

local event = {os.pullEvent()}

Using the table.unpack(table, fromIndex), you can unpack a table to multiple values and pass them as separated parameters to a function. By specifying the fromIndex parameter, you tell which index the unpack should start from so it will skip all values before that index. That is, for example, useful when you want to avoid passing event names to each event function.

function takeParameters(a, b)
    print(a, b)
end

local myTable = {"valueA", "valueB"}
takeParameters(table.unpack(myTable))
-- prints valueA valueB

takeParameters(table.unpack(myTable, 2))
-- prints nil valueB

Now you can process events, for example, like this:

function onDisconnect(feedback, description)
    -- note that description may be nil when basic interface is used!
    print("Stargate disconnected", feedback, description)
end

while true do
    local event = {os.pullEvent()}
    local eventName = event[1]
    if eventName == "stargate_disconnected" then
        -- start from index 2, skipping the event name on index 1
        onDisconnect(table.unpack(event, 2))
--[[
    elif eventName == "other_event" then
        ...
]]--
    end
end

Stargate interface

You will receive these events whenever an interface is connected to the Stargate and the computer.

stargate_chevron_engaged

Fired whenever a chevron is engaged.

Return values

  1. string The event name (stargate_chevron_engaged)
  2. number Count of engaged symbols (from 1 to 9)
  3. number Engaged chevron (chevron identifier from 0 to 8)
  4. boolean true if the chevron was engaged for incoming connection, false if the chevron was locked by dialing this gate
  5. number Encoded symbol (from 0 to 38 - or 35 for the Universe gate)

Basic InterfaceCrystal InterfaceThe symbol is present only when engaged for outgoing connection.
Advanced Crystal Interface The symbol is present even for incoming connection.


stargate_incoming_wormhole

Fired whenever an incoming wormhole forms. The event is fired right after the kawoosh end.

Return values

  1. string The event name (stargate_incoming_wormhole)
  2. number[]Advanced Crystal Interface The connected address

stargate_outgoing_wormhole

Fired whenever an outgoing Wormhole forms. The event is fired right before the kawoosh start.

Return values

  1. string The event name (stargate_outgoing_wormhole)
  2. number[] The dialed address

stargate_disconnected

Fired whenever a connection is ended.

Return values

  1. string The event name (stargate_disconnected)
  2. number The recent feedback code
  3. stringCrystal InterfaceAdvanced Crystal InterfaceA description of the feedback

stargate_reset

Fired whenever a Stargate resets.

Return values

  1. string The event name (stargate_reset)
  2. number The recent feedback code
  3. stringCrystal InterfaceAdvanced Crystal InterfaceA description of the feedback

stargate_deconstructing_entity

Fired whenever an entity enters the wormhole.

Return values

  1. string The event name (stargate_deconstructing_entity)
  2. string The type of the entity (e.g. minecraft:pig)
  3. string The display name of the entity (e.g. player’s name, name set by a nametag or a default mob name)
  4. string UUID of the entity
  5. boolean true when the entity was destroyed by stepping through the wrong end of the wormhole, false otherwise.

stargate_reconstructing_entity

Fired whenever an entity exits the wormhole.

Return values

  1. string The event name (stargate_reconstructing_entity)
  2. string The type of the entity (e.g. minecraft:pig)
  3. string The display name of the entity (e.g. player’s name, name set by a nametag or a default mob name)
  4. string UUID of the entity

stargate_message_received

Fired whenever a Stargate receives a message sent by the sendStargateMessage(message) function

Return values

  1. string The event name (stargate_message_received)
  2. string The message that was sent from an interface connected to the Stargate on the other end of the connection.

See also