Difference between revisions of "Peripheral.find"
From ComputerCraft Wiki
(Created page) |
MKlegoman357 (Talk | contribs) m (Expanded) |
||
| Line 2: | Line 2: | ||
{{Function | {{Function | ||
|name=peripheral.find | |name=peripheral.find | ||
| − | |args= {{type|string}} | + | |args={{type|string}} type |
| − | |returns= | + | |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( | + | |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
| 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
| 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. |