Peripheral detach (event)

From ComputerCraft Wiki
Revision as of 13:45, 11 March 2014 by Scarjit (Talk | contribs)

Jump to: navigation, search
This page needs some serious TLC, stat!
Please help us by cleaning it, fixing it up, or sparing it some love.
(Reason: A demonstration on the use and handling of this event would be beneficial. AfterLifeLochie 16:13, 30 November 2012 (MSK))



Grid Modem.png  Event peripheral_detach
Fired when a peripheral is disconnected (directly adjacent) from the computer.
Returned Object 1 The String value of the side of the now-disconnected peripheral.


Example

p = peripheral.wrap("right") --wraps the peripheral on the right side
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 Modems works I have set up an build like this:

Sample Build
p = peripheral.wrap("")
while true do
event, side = os.pullEvent("peripheral_detach")
print(side) --print's the peripheral Name
end

Every Time you disconnecting an Peripheral it show's:

peripheralname has been disconnected (Where peripheralname is the disconnected Perpheral).