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
The computer will receive these events whenever an interface is connected to a Stargate and the computer.
stargate_chevron_engaged
Fired whenever a chevron is engaged.
Return values
stringThe event name (stargate_chevron_engaged)stringThe peripheral namenumberCount of engaged symbols (from1to9)numberEngaged chevron (chevron identifier from0to8)booleantrueif the chevron was engaged for incoming connection,falseif the chevron was locked by dialing this gatenumberEncoded symbol (from0to38- or35for 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
stringThe event name (stargate_incoming_wormhole)stringThe peripheral namenumber[]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
stringThe event name (stargate_outgoing_wormhole)stringThe peripheral namenumber[]The dialed address
stargate_disconnected
Fired whenever a connection is ended.
Return values
stringThe event name (stargate_disconnected)stringThe peripheral namenumberThe recent feedback codestringCrystal InterfaceAdvanced Crystal InterfaceA description of the feedback
stargate_reset
Fired whenever a Stargate resets.
Return values
stringThe event name (stargate_reset)stringThe peripheral namenumberThe recent feedback codestringCrystal InterfaceAdvanced Crystal InterfaceA description of the feedback
stargate_deconstructing_entity
Fired whenever an entity enters the wormhole.
Return values
stringThe event name (stargate_deconstructing_entity)stringThe peripheral namestringThe type of the entity (e.g.minecraft:pig)stringThe display name of the entity (e.g. player’s name, name set by a nametag or a default mob name)stringUUID of the entitybooleantruewhen the entity was destroyed by stepping through the wrong end of the wormhole,falseotherwise.
stargate_reconstructing_entity
Fired whenever an entity exits the wormhole.
Return values
stringThe event name (stargate_reconstructing_entity)stringThe peripheral namestringThe type of the entity (e.g.minecraft:pig)stringThe display name of the entity (e.g. player’s name, name set by a nametag or a default mob name)stringUUID of the entity
stargate_message_received
Fired whenever a Stargate receives a message sent by the sendStargateMessage(message) function
Return values
stringThe event name (stargate_message_received)stringThe peripheral namestringThe message that was sent from an interface connected to the Stargate on the other end of the connection.
See also
Transceiver
The computer will receiver these events whenever a transceiver is connected as a peripheral.
transceiver_transmission_received
Fired whenever the transceiver receives a transmission on the configured frequency.
Return values
stringThe event name (transceiver_transmission_received)stringThe peripheral namenumberThe configured frequencynumberThe received identification code (IDC)booleanWhether the code matches the configured IDC on the transceiver