Difference between revisions of "Peripheral (API)"

From ComputerCraft Wiki
Jump to: navigation, search
(Monitor)
Line 77: Line 77:
 
|-
 
|-
 
|[[mon.setTextScale|''mon''.setTextScale]]( scale )
 
|[[mon.setTextScale|''mon''.setTextScale]]( scale )
|Sets the size of the text on the Monitor.
+
|Sets the size of the text on the Monitor. Textscale can be between 0.5 and 5, with increments of 0.5.
 
|}
 
|}
 
[[Category:APIs]]
 
[[Category:APIs]]

Revision as of 23:19, 27 July 2012

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.:

fdd = peripheral.wrap("left")
fdd.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

List of methods:

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( line ) Clears the line the cursor is on.
mon.setTextScale( scale ) Sets the size of the text on the Monitor. Textscale can be between 0.5 and 5, with increments of 0.5.