Difference between revisions of "Peripheral.find"

From ComputerCraft Wiki
Jump to: navigation, search
(Created page)
 
m (Expanded)
Line 2: Line 2:
 
{{Function
 
{{Function
 
|name=peripheral.find
 
|name=peripheral.find
|args= {{type|string}} peripheral type
+
|args={{type|string}} type
|returns=A handle to a peripheral of the given type.
+
|returns={{Type|table}} handle1, {{Type|table}} handle2, ... handles to peripherals of the given type
 
|api=peripheral
 
|api=peripheral
 
|addon=ComputerCraft
 
|addon=ComputerCraft
|desc=Returns a handle to a peripheral of the supplied type that can then be used to call methods, as if using peripheral.call(side, method)
+
|desc=Returns a handle to a peripheral of the supplied type that can then be used to call methods, as if using [[peripheral.call]](side, method). The same handle is returned using [[peripheral.wrap]](). '''''Requires ComputerCraft 1.6 or later.'''''
 
|examples=
 
|examples=
 
{{Example
 
{{Example
 
|desc=Finds a monitor and writes 'Hello' on it.
 
|desc=Finds a monitor and writes 'Hello' on it.
|code=local monitor = peripheral.find('monitor') <br/>if monitor then <br/>  monitor.write('Hello') <br/>end
+
|code= local monitor = '''peripheral.find("monitor")'''
 +
 +
if monitor then
 +
  monitor.[[term.write|write]]("Hello")
 +
end
 
|output=If there is a monitor connected 'Hello' will be written on it.
 
|output=If there is a monitor connected 'Hello' will be written on it.
 
}}
 
}}

Revision as of 19:52, 17 April 2014


Grid Redstone.png  Function peripheral.find
Returns a handle to a peripheral of the supplied type that can then be used to call methods, as if using peripheral.call(side, method). The same handle is returned using peripheral.wrap(). Requires ComputerCraft 1.6 or later.
Syntax peripheral.find(string type)
Returns table handle1, table handle2, ... handles to peripherals of the given type
Part of ComputerCraft
API peripheral

Examples

Grid paper.png  Example
Finds a monitor and writes 'Hello' on it.
Code
local monitor = peripheral.find("monitor")

if monitor then
  monitor.write("Hello")
end
Output If there is a monitor connected 'Hello' will be written on it.