Peripheral (API)

From ComputerCraft Wiki
Revision as of 15:04, 28 November 2012 by AfterLifeLochie (Talk | contribs) (Merged in Advanced Monitor methods.)

Jump to: navigation, search

The peripheral API is for interacting with external peripherals, such as the Disk Drive, the Advanced Monitor 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.


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., 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, e.g.:

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


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


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

Methods in italic are available on Advanced Monitors only.

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


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

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, works the same way as term.setCursorPos()
printer.getPageSize() Returns the size of the paper, works the same way as term.getSize()


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.