Difference between revisions of "Peripheral detach (event)"

From ComputerCraft Wiki
Jump to: navigation, search
(updated to match peripheral event page)
 
(One intermediate revision by one other user not shown)
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_detach
 
|name=peripheral_detach
|desc=Fired when a peripheral is disconnected (directly adjacent) from the computer.
+
|desc=Fired when a peripheral is disconnected from the computer locally or remotely (over Network Cables).
|return1=The [[String_(type)|String]] value of the side of the now-disconnected peripheral.
+
|return1=The [[String_(type)|string]] of the side/name of the now disconnected peripheral.
 
}}
 
}}
  
== Example ==
+
{{Example
 
+
|desc=Prints the side/name of a peripheral when it's disconnected
p = peripheral.wrap("right") --wraps the peripheral on the right side
+
|code=
  event, side =os.pullEvent("peripheral_detach") --wait's until the peripheral is disconnected (e.g. Destroyed)
+
  while true do
  print(event) --print's the event name
+
  local event, side = os.pullEvent("peripheral_detach")
print(side) --print's the side where the Peripheral was
+
  print("The peripheral ", side, " has been disconnected")
 +
  end
 +
}}

Latest revision as of 11:18, 25 March 2014



Grid Modem.png  Event peripheral_detach
Fired when a peripheral is disconnected from the computer locally or remotely (over Network Cables).
Returned Object 1 The string of the side/name of the now disconnected peripheral.


Grid paper.png  Example
Prints the side/name of a peripheral when it's disconnected
Code
while true do
  local event, side = os.pullEvent("peripheral_detach")
  print("The peripheral ", side, " has been disconnected")
end