Difference between revisions of "Peripheral (event)"
From ComputerCraft Wiki
(Added a code example) |
m (slight wording tweak) |
||
(3 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
− | |||
− | |||
{{Event | {{Event | ||
|name=peripheral | |name=peripheral | ||
− | |desc=Fired when a peripheral is connected | + | |desc=Fired when a peripheral is connected to the computer locally or remotely (over Network Cables). |
− | |return1= | + | |return1=A [[String_(type)|string]] of the side/name of the connected peripheral. |
}} | }} | ||
{{Example | {{Example | ||
− | |desc=Prints the type of peripheral and side | + | |desc=Prints the type of peripheral and the side of the peripheral when attached |
|code= | |code= | ||
while true do | while true do | ||
− | event, side = os.pullEvent("peripheral") | + | local event, side = os.pullEvent("peripheral") |
print("A "..peripheral.getType(side).." has been attached on the "..side) | print("A "..peripheral.getType(side).." has been attached on the "..side) | ||
end | end | ||
}} | }} | ||
{{Example | {{Example | ||
− | |desc=Prints if | + | |desc=Prints if a modem is attached to the computer. |
|code= | |code= | ||
while true do | while true do | ||
− | event, side = os.pullEvent("peripheral") | + | local event, side = os.pullEvent("peripheral") |
if peripheral.getType(side) == "modem" then | if peripheral.getType(side) == "modem" then | ||
print("A modem has been attached!") | print("A modem has been attached!") | ||
− | |||
end | end | ||
end | end | ||
}} | }} |
Latest revision as of 11:19, 25 March 2014
Event peripheral | |
Fired when a peripheral is connected to the computer locally or remotely (over Network Cables). | |
Returned Object 1 | A string of the side/name of the connected peripheral. |