Difference between revisions of "Peripheral detach (event)"

From ComputerCraft Wiki
Jump to: navigation, search
(updated to match peripheral event page)
 
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)
+
print(event) --print's the event name
+
print(side) --print's the side where the Peripheral was
+
 
+
== Advanced Example ==
+
For this tutorial you need to know how [[Wired Modem]]s works
+
I have set up an build like this:
+
[[File:Periperal_detach.png|200px|thumb|left|Sample Build]]
+
 
+
p = peripheral.wrap("")
+
 
  while true do
 
  while true do
event, side = os.pullEvent("peripheral_detach")
+
  local event, side = os.pullEvent("peripheral_detach")
print(side) --print's the peripheral Name
+
  print("The peripheral ", side, " has been disconnected")
 
  end
 
  end
Every Time you disconnecting an Peripheral it show's:
+
}}
 
+
peripheralname has been disconnected (Where peripheralname is the disconnected Perpheral).
+

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