Difference between revisions of "Peripheral (API)"

From ComputerCraft Wiki
Jump to: navigation, search
m (Fix all teh typos!)
(Completed merge of peripheral maps to their actual item/block pages. (+1 usability))
Line 43: Line 43:
 
|}
 
|}
 
==Monitor==
 
==Monitor==
'''''monitor'' stands for the variable you wrapped the monitor to.'''
+
[[Monitor#Peripheral_Functions|Monitor Peripheral functions]] have been moved to the [[Monitor]] page.
''Example:'' monitor = peripheral.wrap( "top" )
+
In addition, the [[Advanced_Monitor#Peripheral_Functions|Advanced Monitor Peripheral functions]] have been moved to the [[Advanced Monitor]] page.
 
+
Methods in ''italic'' are available on [[Advanced Monitor|Advanced Monitors]] only.
+
 
+
{| class="wikitable"
+
!style="background:#EEE" width="210px"|Method name
+
!style="background:#EEE" width="*"|Description
+
|-
+
|[[term.write|monitor.write]]()
+
|Write to the Monitor's screen.
+
|-
+
|[[term.scroll|monitor.scroll]](n)
+
|Scrolls the monitor screen.
+
|-
+
|[[term.setCursorPos|monitor.setCursorPos]](x, y)
+
|Sets the cursor position on the Monitor.
+
|-
+
|[[term.setCursorBlink|monitor.setCursorBlink]](b)
+
|Enables or disables cursor blinking.
+
|-
+
|[[term.getCursorPos|monitor.getCursorPos]]()
+
|Returns two arguments containing the x and the y position of the cursor on the Monitor.
+
|-
+
|[[term.getSize|monitor.getSize]]()
+
|Returns two arguments containing the x and the y values stating the size of the Monitor.
+
|-
+
|[[term.clear|monitor.clear]]()
+
|Clears the Monitor.
+
|-
+
|[[term.clearLine|monitor.clearLine]]()
+
|Clears the line the cursor is on.
+
|-
+
|[[monitor.setTextScale|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
+
|-
+
|''[[term.setTextColor|monitor.setTextColor]]([[colors (API)#colors|color]])''
+
|Sets the text-color of the [[Advanced Monitor]]. Available only to [[Advanced Monitor|Advanced Monitors]]
+
|-
+
|''[[term.setBackgroundColor|monitor.setBackgroundColor]]([[colors (API)#colors|color]])''
+
|Sets the background-color of the [[Advanced Monitor]]. Available only to [[Advanced Monitor|Advanced Monitors]]
+
|}
+
  
 
==Printer==
 
==Printer==
'''''printer'' stands for the variable you wrapped the printer to.'''
+
[[Printer#Peripheral_Functions|Printer Peripheral functions]] have been moved to the [[Printer]]page.
''Example:'' printer = peripheral.wrap( "right" )
+
 
+
{| class="wikitable"
+
!style="background:#EEE" width="200px"|Method name
+
!style="background:#EEE" width="*"|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()]]
+
|}
+
  
 
==Computers==
 
==Computers==
'''''computer'' stands for the variable you wrapped the computer to.'''
+
[[Console#Peripheral_Functions|Computer Peripheral functions]] have been moved to the [[Computer]] page.
''Example:'' computer = peripheral.wrap( "top" )
+
In addition, the [[Advanced_Computer#Peripheral_Functions|Advanced Computer Peripheral functions]] have been moved to the [[Advanced Computer]] page.
  
{| class="wikitable"
 
!style="background:#EEE" width="210px"|Method name
 
!style="background:#EEE" width="*"|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.
 
|}
 
 
[[Category:APIs]]
 
[[Category:APIs]]

Revision as of 00:00, 29 November 2012

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.

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

Monitor Peripheral functions have been moved to the Monitor page. In addition, the Advanced Monitor Peripheral functions have been moved to the Advanced Monitor page.

Printer

Printer Peripheral functions have been moved to the Printerpage.

Computers

Computer Peripheral functions have been moved to the Computer page. In addition, the Advanced Computer Peripheral functions have been moved to the Advanced Computer page.