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

disk API attempt to call nil

Started by Sevenarth, 09 April 2012 - 10:41 AM
Sevenarth #1
Posted 09 April 2012 - 12:41 PM
hi all!
I'm writing a program to create floppy copies, but i get "attempt to call nil" on disk API, I also tried putting os.loadAPI("disk"), but nothing changes

print("Sending signal..")
rs.setOutput("top", true)
os.sleep(0.5)
rs.setOutput("top", false)
os.sleep(0.3)
dsk, side = os.pullEventRaw()
if dsk == "disk" then
   print("Writing...")
   file,err = io.open(disk.getMountPath(side).."/access", "w")
   file:write("please open the door")
   print("File writed!")
   file:close()
   print("Ejecting..")
   disk.setLabel(side, "Magnetic access card")
   os.sleep(0.3)  
   disk.eject(side)
end
Here's the code.
I get "attempt to call nil" on line 9, exactly:

   file,err = io.open(disk.getMountPath(side).."/access", "w")
Help..

if i set "disk/access", it writes successfully but stops at line 14

sorry for bad english.. i'm italian
Advert #2
Posted 09 April 2012 - 04:20 PM
I'm not sure what's causing your problem, it seems to work fine for me.

I'd try using a loop, along with os.pullEventRaw so you don't capture some other event and then never write the disk.
Sevenarth #3
Posted 09 April 2012 - 04:43 PM
Now it's working.. i deleted the first os.pullEventRaw() call, and works… (in the code i posted there's just the second call)…

i used the first call because when I set redstone state to false, it calls this event.