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

Always eject Disk

Started by Kouksi44, 03 May 2013 - 10:55 AM
Kouksi44 #1
Posted 03 May 2013 - 12:55 PM
i tried to make little program that ejects a floppy as soon as its injected. But every time I am starting the program, I am getting the same error:'=' expected.

Code:

function Check()
local x= peripheral.isPresent("left")
local y= peripheral.getType("left")
If x==true and y=="drive" then disk.eject("left") end
end

Check()

I just don't get it !! What's wrong with this code ????
Lyqyd #2
Posted 03 May 2013 - 01:03 PM
Split into new topic.

You have capitalized `if`. It needs to be lower case.
Kouksi44 #3
Posted 03 May 2013 - 02:02 PM
oh! thx!!
PixelToast #4
Posted 03 May 2013 - 03:27 PM
here is a better implementation:

local oldpull=os.pullEventRaw
function os.pullEventRaw(...)
local p={coroutine.yield(...)}
if p[1]=="disk" then
peripheral.call(p[2],"eject")
end
return unpack(p)
end
-- eject disks
os.pullEventRaw=oldpull
-- stop ejecting disks