Difference between revisions of "Peripheral detach (event)"
From ComputerCraft Wiki
Line 10: | Line 10: | ||
p = peripheral.wrap("right") --wraps the peripheral on the right side | 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) | + | event, side = os.pullEvent("peripheral_detach") --wait's until the peripheral is disconnected (e.g. Destroyed) |
print(event) --print's the event name | print(event) --print's the event name | ||
print(side) --print's the side where the Peripheral was | 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 | ||
+ | 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). |
Revision as of 13:45, 11 March 2014
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)) |
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:
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).