This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
TheCodMan78's profile picture

Is there a way to detect if a floppy disk is inserted into a disk drive?

Started by TheCodMan78, 16 April 2013 - 12:57 PM
TheCodMan78 #1
Posted 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?
Sammich Lord #2
Posted 16 April 2013 - 03:00 PM
Read up on the OS API
http://www.computercraft.info/wiki/Os.pullEvent
But it is the "disk" event.
TheCodMan78 #3
Posted 16 April 2013 - 03:03 PM
Read up on the OS API
http://www.computerc...ki/Os.pullEvent
But it is the "disk" event.
Okay, thanks. Once again. :P/>
SuicidalSTDz #4
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*
TheCodMan78 #5
Posted 16 April 2013 - 03:13 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*
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.
SuicidalSTDz #6
Posted 16 April 2013 - 03:16 PM
while true do
 local _, side = os.pullEvent("disk")
 disk.eject(side)
end
TheCodMan78 #7
Posted 16 April 2013 - 03:17 PM
Thanks! :)/>
SuicidalSTDz #8
Posted 16 April 2013 - 03:19 PM
No problemo ^_^/>
TheCodMan78 #9
Posted 16 April 2013 - 03:20 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*
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.
But, I'm not able to type anything while that codes running.
Sammich Lord #10
Posted 16 April 2013 - 03:21 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*
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.
But, I'm not able to type anything while that codes running.
Run it in parallel with shell.

parallel.waitForAny(function() shell.run("shell") end, functionToCallThatCode)
SuicidalSTDz #11
Posted 16 April 2013 - 03:22 PM
Dammit Human :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/>
Sammich Lord #12
Posted 16 April 2013 - 03:24 PM
Dammit Human :P/>

EDIT: Ninja'd
You can't win every time :P/>
TheCodMan78 #13
Posted 16 April 2013 - 03:25 PM
Thanks for all your help, both of you. :D/>
SuicidalSTDz #14
Posted 16 April 2013 - 03:27 PM
You can't win every time :P/>
I can try <_</>