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
string
The event name (stargate_chevron_engaged
)string
The peripheral namenumber
Count of engaged symbols (from1
to9
)number
Engaged chevron (chevron identifier from0
to8
)boolean
true
if the chevron was engaged for incoming connection,false
if the chevron was locked by dialing this gatenumber
Encoded symbol (from0
to38
- or35
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
string
The event name (stargate_incoming_wormhole
)string
The 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
string
The event name (stargate_outgoing_wormhole
)string
The peripheral namenumber[]
The dialed address
stargate_disconnected
Fired whenever a connection is ended.
Return values
string
The event name (stargate_disconnected
)string
The peripheral namenumber
The recent feedback codestring
Crystal InterfaceAdvanced Crystal InterfaceA description of the feedback
stargate_reset
Fired whenever a Stargate resets.
Return values
string
The event name (stargate_reset
)string
The peripheral namenumber
The recent feedback codestring
Crystal InterfaceAdvanced Crystal InterfaceA description of the feedback
stargate_deconstructing_entity
Fired whenever an entity enters the wormhole.
Return values
string
The event name (stargate_deconstructing_entity
)string
The peripheral namestring
The type of the entity (e.g.minecraft:pig
)string
The display name of the entity (e.g. player’s name, name set by a nametag or a default mob name)string
UUID of the entityboolean
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
string
The event name (stargate_reconstructing_entity
)string
The peripheral namestring
The type of the entity (e.g.minecraft:pig
)string
The display name of the entity (e.g. player’s name, name set by a nametag or a default mob name)string
UUID of the entity
stargate_message_received
Fired whenever a Stargate receives a message sent by the sendStargateMessage(message)
function
Return values
string
The event name (stargate_message_received
)string
The peripheral namestring
The 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
string
The event name (transceiver_transmission_received
)string
The peripheral namenumber
The configured frequencynumber
The received identification code (IDC)boolean
Whether the code matches the configured IDC on the transceiver