ComputerCraft Integration

Stargate Interface

Stargates can be controlled by ComputerCraft computers using a ComputerCraft Stargate Interface block. This block functions as a ComputerCraft peripheral and should be placed somewhere underneath the bottom row of ring blocks.


Methods

The stargate interface peripheral provides the following methods.

Addresses passed as arguments may be either 7 or 9 characters, with or without hyphens.
stargateState()
Returns two values, a string indicating the state of the stargate, and the number of engaged chevrons.
The state string is one of the following values:

Idle
Operating and ready to dial
Dialling
In the process of dialling an address
Connecting
Finished dialling, wormhole in transient phase
Connected
Wormhole is stable

energyAvailable()
Returns the amount of energy in the gate's internal buffer plus the buffers of any attached Stargate Power Units. This is the energy available for the next dialling operation.

Energy is measured in stargate energy units (SU). Relationships between SU and other energy units are:

IndustrialCraft
1 SU = 20 EU
Thermal Expansion
1 SU = 80 RF

energyToDial(address)
Returns the amount of energy that would be needed to connect to the stargate at the given address.

localAddress()
Returns the address of the attached stargate.

remoteAddress()
Returns the address of the connected stargate, or nil if not connected.

dial(address)
Dials the given address.

disconnect()
Closes any open connection.

irisState()
Returns a string indicating the state of the iris: Closed, Opening, Open, Closing, or nil if no iris is fitted.

closeIris()
Closes the iris, if fitted.

openIris()
Opens the iris, if fitted.

Exception Handling

Methods of the stargate interface throw an exception in the event of an error. If not caught, this will terminate the program. If this is inconvenient, you can use the pcall function to catch the exception and take some other action, for example:

ok, result = pcall(sg.dial, address)
if ok then
  print("Dialling succeeded")
else
  print("Dialling failed: ", result)

Events

Stargate events consist of two values, an event name, and an argument object having methods that provide additional information. The argument object has the following methods in common for all event types:

Method
Return type
Value
world()
string
The name of the world containing the stargate
dimension()
integer
The dimension ID of the world
x()
y()
z()
integer
Coordinates of the stargate base block

The argument objects for individual events also have additional methods as listed below.

Addresses returned by these methods are always 9 characters without hyphens.

Event name
Description
Method
Return type
Value
sgDialIn
An incoming connection has been initiated
address()
string
Address of stargate connecting in
sgDialOut
An outgoing connection has been initiated
address()
string
Address being dialled
sgChevronEngaged
A chevron has been engaged during dialling
chevron()
integer
Chevron number (1 to 9)
symbol()
string
Address symbol encoded
sgStargateStateChange
State of stargate has changed
oldState()
string
Previous state
newState()
string
Current state
sgIrisStateChange
State of iris has changed
oldState() string Previous state
newState() string Current state

Example Code

Some small Lua programs exercising the functions of the interface.

Programs Library Code
dial
disconnect
energy
events
interactive
iris
state
config

Code as zip file