Difference between revisions of "Peripheral (event)"
From ComputerCraft Wiki
(Created event page) |
(Added a code example) |
||
| Line 4: | Line 4: | ||
|name=peripheral | |name=peripheral | ||
|desc=Fired when a peripheral is connected (directly adjacent) to the computer. | |desc=Fired when a peripheral is connected (directly adjacent) to the computer. | ||
| − | |return1=The [[String_(type)| | + | |return1=The [[String_(type)|string]] value of the side of the connected peripheral. |
| + | }} | ||
| + | {{Example | ||
| + | |desc=Prints the type of peripheral and side when peripheral is attached | ||
| + | |code= | ||
| + | while true do | ||
| + | event, side = os.pullEvent("peripheral") | ||
| + | print("A "..peripheral.getType(side).." has been attached on the "..side) | ||
| + | end | ||
| + | }} | ||
| + | {{Example | ||
| + | |desc=Prints if it found the peripheral it was looking for ( in this example modem, more peripheral type here [[peripheral.getType]] | ||
| + | |code= | ||
| + | while true do | ||
| + | event, side = os.pullEvent("peripheral") | ||
| + | if peripheral.getType(side) == "modem" then | ||
| + | print("A modem has been attached!") | ||
| + | break | ||
| + | end | ||
| + | end | ||
}} | }} | ||
Revision as of 18:39, 18 January 2013
| This page needs some serious TLC, stat! Please help us by cleaning it, fixing it up, or sparing it some love.
(Reason: A demonstration on the use and handling of this event would be beneficial. AfterLifeLochie 16:13, 30 November 2012 (MSK)) |
| Fired when a peripheral is connected (directly adjacent) to the computer. | |
| Returned Object 1 | The string value of the side of the connected peripheral. |
| Prints if it found the peripheral it was looking for ( in this example modem, more peripheral type here peripheral.getType | |
| Code |
while true do
event, side = os.pullEvent("peripheral")
if peripheral.getType(side) == "modem" then
print("A modem has been attached!")
break
end
end
|