Difference between revisions of "Peripheral (event)"

From ComputerCraft Wiki
Jump to: navigation, search
m (Removed the NeedsWork.)
m (slight wording tweak)
 
(2 intermediate revisions by 2 users not shown)
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=A [[String_(type)|string]] of the side/name of the connected peripheral.
 
}}
 
}}
 
{{Example
 
{{Example
|desc=Prints the type of peripheral and side when peripheral is attached
+
|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 it found the peripheral it was looking for ( in this example modem, more peripheral type here [[peripheral.getType]]
+
|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!")
    break
 
 
   end
 
   end
 
  end
 
  end
 
}}
 
}}

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