Difference between revisions of "Peripheral (event)"

From ComputerCraft Wiki
Jump to: navigation, search
(better coding habits)
m (slight wording tweak)
 
Line 2: Line 2:
 
|name=peripheral
 
|name=peripheral
 
|desc=Fired when a peripheral is connected to the computer locally or remotely (over Network Cables).
 
|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=A [[String_(type)|string]] of the side/name of the connected peripheral.
 
}}
 
}}
 
{{Example
 
{{Example

Latest revision as of 11:19, 25 March 2014



Grid Modem.png  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.


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