This page documents the OpenComputers Stargate interface block provided by SGCraft. The interface exposes Stargate control callbacks through a component named stargate and can also relay OpenComputers network packets through an installed LAN card upgrade.
- Dependency:
sgcraft - Label:
integration-required
stargate
- Reading local Stargate state, chevron count, and connection direction.
- Checking available energy and estimating the cost of a dial attempt.
- Dialing and disconnecting gates from Lua scripts.
- Controlling an iris upgrade.
- Sending structured messages to the remote gate and receiving Stargate events.
- Rebroadcasting OpenComputers wireless packets through connected gates when a LAN card is installed in the interface block.
- Place the OpenComputers Stargate Interface block adjacent to a merged Stargate.
- The component is exposed as
component.stargate. - The interface has one internal upgrade slot.
- Installing an OpenComputers
lanCarditem in that slot enables Stargate packet rebroadcast for OpenComputers network packets.
- Syntax:
stargateState(): string, number, string - Purpose: Return the current Stargate state, number of engaged chevrons, and connection direction.
- Returns:
state: stringHuman-readable Stargate state description.chevrons: numberNumber of engaged chevrons.direction: stringOutgoing,Incoming, or an empty string when not connected.
- Usage notes:
- If no Stargate is connected to the interface, this returns
Offline, 0, "".
- If no Stargate is connected to the interface, this returns
- Syntax:
energyAvailable(): number - Purpose: Return the energy currently available to the attached Stargate.
- Returns:
- Available dial energy.
- Syntax:
energyToDial(address: string): number[, string] - Purpose: Estimate the energy required to dial a normalized Stargate address.
- Parameters:
address: stringDestination Stargate address.
- Returns:
- Required energy on success.
nil, messageif the local Stargate is missing, the address is invalid, or the destination cannot be found.
- Usage notes:
- The address is normalized before lookup.
- The cost depends on the coordinate distance between the local and remote gates.
- Syntax:
localAddress(): string - Purpose: Return the home address of the attached Stargate.
- Returns:
- Local Stargate address, or an empty string if the interface is not attached to a gate.
- Syntax:
remoteAddress(): string[, string] - Purpose: Return the address of the currently connected remote gate.
- Returns:
- Remote address when connected.
- An empty string when the local gate is idle.
nil, messageif no Stargate is connected to the interface.
- Syntax:
dial(address: string): boolean[, string] - Purpose: Start a dial attempt to the specified destination address.
- Parameters:
address: stringDestination Stargate address.
- Returns:
trueon success.nil, messageif dialing fails.
- Usage notes:
- The address is normalized before dialing.
- Any Stargate-side error is returned as the second result.
- Syntax:
disconnect(): boolean[, string] - Purpose: Close the current Stargate connection.
- Returns:
trueon success.nil, messageif there is no connected gate or the disconnect attempt fails.
- Syntax:
irisState(): string - Purpose: Return the current iris state description.
- Returns:
- Iris state string.
- Usage notes:
- If no iris upgrade is installed, this returns
Offline.
- If no iris upgrade is installed, this returns
- Syntax:
openIris(): boolean[, string] - Purpose: Start opening the iris.
- Returns:
trueon success.nil, messageif there is no connected Stargate or no iris upgrade is installed.
- Syntax:
closeIris(): boolean[, string] - Purpose: Start closing the iris.
- Returns:
trueon success.nil, messageif there is no connected Stargate or no iris upgrade is installed.
- Syntax:
sendMessage(...): boolean[, string] - Purpose: Send one Stargate application-layer message to the currently connected remote gate.
- Parameters:
...Zero or more Lua values. The interface forwards them as an object array.
- Returns:
trueon success.nil, messageif the gate is not connected or the send fails.
- Usage notes:
- The receiver gets the payload through the
sgMessageReceivedevent. - Arguments are forwarded in order without an extra wrapper table.
- The receiver gets the payload through the
The interface posts these events to reachable OpenComputers machines through computer.signal.
- Syntax:
sgStargateStateChange(newState, oldState) - Purpose: Fired when the Stargate state description changes.
- Parameters:
newState: stringNew human-readable state.oldState: stringPrevious human-readable state.
- Syntax:
sgDialOut(address) - Purpose: Fired when the local Stargate begins an outgoing connection to
address.
- Syntax:
sgDialIn(address) - Purpose: Fired when the local Stargate receives an incoming connection from
address.
- Syntax:
sgChevronEngaged(chevronCount, symbol) - Purpose: Fired each time another chevron locks during dialing.
- Parameters:
chevronCount: numberNumber of chevrons engaged after the lock.symbol: stringThe symbol that was just locked.
- Syntax:
sgIrisStateChange(newState, oldState) - Purpose: Fired when the iris state description changes.
- Syntax:
sgMessageReceived(...) - Purpose: Fired when the remote Stargate sends a message through
sendMessage(...). - Parameters:
...The exact values forwarded by the sender.
- Every Stargate base tile joins the OpenComputers wireless network internally.
- If an interface block contains a LAN card, incoming
network.messagepackets can be forwarded through an active Stargate to the connected remote gate. - Packets are only forwarded while their TTL is still above zero.
- The default wireless rebroadcast strength used by the Stargate-side bridge is
50.
local component = require("component")
local event = require("event")
local sg = component.stargate
local state, chevrons, direction = sg.stargateState()
print("State:", state, chevrons, direction)
print("Local address:", sg.localAddress())
local ok, err = sg.dial("ABCD-EFG-HI")
if not ok then
error(err)
end
while true do
local _, name, a, b = event.pull()
if name == "sgChevronEngaged" then
print("Chevron", a, "locked symbol", b)
elseif name == "sgStargateStateChange" then
print("State changed:", a, "(was", b .. ")")
end
endstargatetech2network