Peripheral (API)

From ComputerCraft Wiki
Revision as of 21:24, 14 October 2012 by 72.193.42.72 (Talk) (Monitor)

Jump to: navigation, search

The peripheral API is for interacting with external peripherals, such as the disk drive and monitor.
Consoles and Turtles are also considered peripherals and you can interface two adjacent computers, although in a more limited fashion compared to rednet. Both Computers and Turtles provide the same methods: turnOn, shutdown, reboot, getID.

Methods

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 from that peripheral, as if calling peripheral.call(), e.g.:

m = peripheral.wrap("left")
m.someMethod()
- is the same as -
peripheral.call("left","someMethod")

Events

Event name Description Parameters
peripheral Fired when peripheral is attached side
peripheral_detach Fired when peripheral is removed side

Monitor

faggot

mon stands for the variable you wrapped the monitor to. Example: mon = peripheral.wrap( "top" )

Method name Description
mon.write() Write to the Monitor's screen.
mon.scroll( n ) Scrolls the monitor screen.
mon.setCursorPos( x, y ) Sets the cursor position on the Monitor.
mon.setCursorBlink( b ) Enables or disables cursor blinking.
mon.getCursorPos() Returns two arguments containing the x and the y position of the cursor on the Monitor.
mon.getSize() Returns two arguments containing the x and the y values stating the size of the Monitor.
mon.clear() Clears the Monitor.
mon.clearLine() Clears the line the cursor is on.
mon.setTextScale( scale ) Sets the size of the text on the Monitor. Textscale can be between 1.0 and 5.0, with increments of 0.5

Printer

printer stands for the variable you wrapped the printer to. Example:

printer = peripheral.wrap( "right" )

printer.newPage()

List of methods:

Method name Description
printer.newPage() Starts a new page. Returns true if page got started, false if not.
printer.endPage() Ends the page and prints the page to the output tray. Returns true if page was ended, false if not.
printer.write( text ) Writes text to the paper, works the same way as term.write()
printer.setPageTitle( text ) Sets the title of the page.
printer.getPaperLevel() Returns the amount of paper available in the paper tray.
printer.getInkLevel() Returns the amount of ink in the ink slot.
printer.getCursorPos() Returns the coordinates of the cursor on the paper, works the same way as term.getCursorPos()
printer.setCursorPos( x, y ) Sets the cursor pos.
printer.getPageSize() Returns the size of the paper, works the same way as term.getSize()

Computers

List of methods:

computer stands for the variable you wrapped the computer to. Example: computer = peripheral.wrap( "top" )

Method name Description
computer.turnOn() Turns on the Computer or Turtle.
computer.shutdown() Shuts off the Computer or Turtle.
computer.reboot() Reboots the Computer or Turtle.
computer.getID() Gets the ID of the Computer or Turtle.