This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Is there a way to detect if a floppy disk is inserted into a disk drive?
Started by TheCodMan78, 16 April 2013 - 12:57 PMPosted 16 April 2013 - 02:57 PM
Hey guys, I was wondering if there's a way to detect if a floppy disk is entered into a disk drive?
Posted 16 April 2013 - 03:00 PM
Posted 16 April 2013 - 03:03 PM
Okay, thanks. Once again. :P/>
Posted 16 April 2013 - 03:09 PM
*cough*
while true do
local event,side = os.pullEvent()
if event == "disk" then
print("Someone is tryin to steal muh code on: "..side)
end
end
*cough*Posted 16 April 2013 - 03:13 PM
What I'm basically trying to do is if a disk is inserted, it'd be ejected. I just don't know how to get which side the disk was inserted, and tell the computer to eject the disk whichever side it's on.*cough**cough*while true do local event,side = os.pullEvent() if event == "disk" then print("Someone is tryin to steal muh code on: "..side) end end
Posted 16 April 2013 - 03:16 PM
while true do
local _, side = os.pullEvent("disk")
disk.eject(side)
end
Posted 16 April 2013 - 03:17 PM
Thanks! :)/>
Posted 16 April 2013 - 03:19 PM
No problemo ^_^/>
Posted 16 April 2013 - 03:20 PM
But, I'm not able to type anything while that codes running.What I'm basically trying to do is if a disk is inserted, it'd be ejected. I just don't know how to get which side the disk was inserted, and tell the computer to eject the disk whichever side it's on.*cough**cough*while true do local event,side = os.pullEvent() if event == "disk" then print("Someone is tryin to steal muh code on: "..side) end end
Posted 16 April 2013 - 03:21 PM
Run it in parallel with shell.But, I'm not able to type anything while that codes running.What I'm basically trying to do is if a disk is inserted, it'd be ejected. I just don't know how to get which side the disk was inserted, and tell the computer to eject the disk whichever side it's on.*cough**cough*while true do local event,side = os.pullEvent() if event == "disk" then print("Someone is tryin to steal muh code on: "..side) end end
parallel.waitForAny(function() shell.run("shell") end, functionToCallThatCode)
Posted 16 April 2013 - 03:22 PM
Dammit Human :P/>
EDIT: Ninja'd
EDIT: Here is what it should look like :P/>
EDIT: Ninja'd
local wait = function() -- or local function wait()
while true do
local _, side = os.pullEvent("disk")
disk.eject(side)
end
end
parallel.waitForAny(function() shell.run("rom/programs/shell") end, wait)
EDIT: Here is what it should look like :P/>
Posted 16 April 2013 - 03:24 PM
You can't win every time :P/>Dammit Human :P/>
EDIT: Ninja'd
Posted 16 April 2013 - 03:25 PM
Thanks for all your help, both of you. :D/>
Posted 16 April 2013 - 03:27 PM
I can try <_</>You can't win every time :P/>