-
-
Notifications
You must be signed in to change notification settings - Fork 69
Computer Craft API
To use the API, connect a computer to an Essentia Provider. This can be done directly by placing the computer next to the provider, or via modems.
Once connected you can then access the provider through the peripheral module.
For example ep = peripheral.find("EssentiaProvider")
Once the provider peripheral is accessed, you are ready to access the essentia storage system.
An example program is provided here.
Arguments: None
Returns: Help object.
The help object contains the same function calls as the provider object. When called, help about the function is displayed.
Arguments: None
Returns: Boolean, true if the provider is powered on and connected, false otherwise.
Example:
if( ep.isOnline() ) then
Arguments: None
Returns: Name and amount of each essentia type stored as a list.
You will probably want to wrap the result list into a table for easier access.
Example:
essTable = {ep.getAspects()}
name1 = essTable[1]
amount1 = essTable[2]
name2 = essTable[3]
amount2 = essTable[4]
Arguments: AspectName1, AspectName2, etc
Returns: Amount(s) of essentia stored in the system for the specified aspect(s).
Example:
ordoAmt = ep.getAmount("ordo")
ordoAmt, metoAmt = ep.getAmount("ordo","meto")
amountTable = {ep.getAmount("aqua","ignis","ordo","herba","bestia")}
Arguments: (optional)AspectName1, AspectName2, etc
Returns: Boolean, true if registered, false otherwise.
Registers this computer for essentia events. When essentia amounts on the network changes, this computer will receive a notification event.
If aspect arguments are provided, only events for those aspects will be generated. If no arguments are provided, any change will generate an event.
Example:
ep.registerAsWatcher()
ep.registerAsWatcher("ordo")
ep.registerAsWatcher("ordo","meto")
Arguments: (optional)AspectName1, AspectName2, etc
Returns: Boolean, true if unregistered, false otherwise.
Unregisters this computer for essentia events.
If aspect arguments are provided, only unregister for those aspects. If no arguments are provided, unregister for all.
Examples:
ep.unregisterAsWatcher()
ep.unregisterAsWatcher("ordo")
ep.unregisterAsWatcher("meto","ordo")
When registered as a watcher, the computer will receive essentia events.
These events come in three types and are differentiated by an ID number.
To listen for these event you use os.pullEvent.
Example for listening just for essentia events
event = { os.pullEvent("essentia") }
Example for listening for any event
event = { os.pullEvent() }
if ( event[1] == "essentia" ) then
###Essentia Change Event
ID: 1
Arguments: string:Aspect Name, int:Change Amount
The essentia event is generated any time a watched essentia amount changes. For example if you place a vial of Ignis essentia into the Essentia Terminal the following event would be generated:
["essentia"][1]["ignis"][8]
Example:
event = { os.pullEvent() }
if ( event[1] == "essentia" ) then
if( event[2] == 1 ) then
name = event[3]
change = event[4]
###Power Event
ID: 2
Arguments: boolean:Is Powered
The power event is generated when the providers power state changes. For example if the provider is disconnected from the network the following event would be generated:
["essentia"][2][false]
Example:
event = { os.pullEvent() }
if ( event[1] == "essentia" ) then
if( event[2] == 2 ) then
isOnline = event[3]
##Detach Event
ID: 2
Arguments: None
The detach event is generated when the computer can no longer communicate with the provider. This can occur if the provider is destroyed, if the ComputerCraft network cable or modem is destroyed, or if the modem is deactivated. In any case, the provider is no longer able to be queried. Example event:
["essentia"][3]