Difference between revisions of "Peripheral (event)"

From ComputerCraft Wiki
Jump to: navigation, search
m (Please don't remove {{NeedsWork}} without proofreading document contents.)
(better coding habits)
Line 1: Line 1:
 
{{Event
 
{{Event
 
|name=peripheral
 
|name=peripheral
|desc=Fired when a peripheral is connected (directly adjacent) to the computer.
+
|desc=Fired when a peripheral is connected to the computer locally or remotely (over Network Cables).
 
|return1=The [[String_(type)|string]] value of the side of the connected peripheral.
 
|return1=The [[String_(type)|string]] value of the side of the connected peripheral.
 
}}
 
}}
Line 8: Line 8:
 
|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
Line 16: Line 16:
 
|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!")
    break
 
 
   end
 
   end
 
  end
 
  end
 
}}
 
}}

Revision as of 10:08, 28 October 2013



Grid Modem.png  Event peripheral
Fired when a peripheral is connected to the computer locally or remotely (over Network Cables).
Returned Object 1 The string value of the side of the connected peripheral.


Grid paper.png  Example
Prints the type of peripheral and the side of the peripheral when attached
Code
while true do
  local event, side = os.pullEvent("peripheral")
  print("A "..peripheral.getType(side).." has been attached on the "..side)
end



Grid paper.png  Example
Prints if a modem is attached to the computer.
Code
while true do
 local event, side = os.pullEvent("peripheral")
 if peripheral.getType(side) == "modem" then
   print("A modem has been attached!")
 end
end