Peripheral (API)

From ComputerCraft Wiki
Revision as of 13:48, 2 May 2012 by Onionnion (Talk | contribs) (Added link to Wikipedia page explaining peripherals)

Jump to: navigation, search

The peripheral API is for interacting with external peripherals, such as the disk drive and monitor.

Method name Description
peripheral.isPresent( side ) Returns true if a peripheral is present on side.
peripheral.getType( side ) Returns the type or peripheral present on side, nothing returned if side is empty.
peripheral.getMethods( side ) Returns a table containing all methods for peripheral on side.
peripheral.call( side, methodName, param1, param2, ... ) Sends a function call to peripheral located on side. Return values match those of called method.

Note: methodName is a string.

peripheral.wrap( side ) Returns a handle to the peripheral located on side. If assigned to a variable, it can be used to call all methods available, as if calling peripheral.call(), e.g.:

fdd = peripheral.wrap("left")
fdd.isPresent()
- is the same as -
peripheral.call("left","isPresent")

When new peripherals are added and removed from the computer, the events peripheral' and peripheral_detach will fire, with the side as a parameter. Consoles and Turtles are also considered peripherals and you can interface two adjacent computers, although in a more limited fashion, compared to with rednet. Both Computers and Turtles provide the same methods: turnOn, shutdown, reboot, getID.