Difference between revisions of "Peripheral (event)"

From ComputerCraft Wiki
Jump to: navigation, search
(Added a code example)
m (Removed the NeedsWork.)
Line 1: Line 1:
{{NeedsWork|A demonstration on the use and handling of this event would be beneficial. ''[[User:AfterLifeLochie|AfterLifeLochie]] 16:13, 30 November 2012 (MSK)''}}
 
 
 
{{Event
 
{{Event
 
|name=peripheral
 
|name=peripheral

Revision as of 11:14, 6 May 2013



Grid Modem.png  Event peripheral
Fired when a peripheral is connected (directly adjacent) to the computer.
Returned Object 1 The string value of the side of the connected peripheral.


Grid paper.png  Example
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



Grid paper.png  Example
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