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

Disk API

Started by ebernerd, 08 February 2013 - 10:49 AM
ebernerd #1
Posted 08 February 2013 - 11:49 AM
I am building a theme park in Tekkit, and I want to make it so the ticket is made so that the computer check the label. I know what the disk API is, but how do I use it?
ChunLing #2
Posted 08 February 2013 - 11:53 AM
Knowing what it is would include knowing how to use it. In this particular case you want to use disk.getLabel() somehow.
LBPHacker #3
Posted 08 February 2013 - 12:01 PM
What do you mean by how to use it?

OK. In a nutshell…

When you insert a disk, CC mounts it. YOu can reach its data in disk/ directory, or disk2/ if that's the second mounted disk, or disk3/, etc.

So opening a file from a disk is like
local handle = fs.open("disk/myfile", "r")

When you have only one disk drive, that's easy like that. But what's up with multiple disk drives?

You can get the path ("disk" or "disk2" etc.) using
disk.getMountPath(side)
where side is the side where the disk drive you want to use is.

EDIT: Sorry, I misunderstood - I thought you haven't ever used disk API.
ebernerd #4
Posted 08 February 2013 - 12:36 PM
What do you mean by how to use it?

OK. In a nutshell…

When you insert a disk, CC mounts it. YOu can reach its data in disk/ directory, or disk2/ if that's the second mounted disk, or disk3/, etc.

So opening a file from a disk is like
local handle = fs.open("disk/myfile", "r")

When you have only one disk drive, that's easy like that. But what's up with multiple disk drives?

You can get the path ("disk" or "disk2" etc.) using
disk.getMountPath(side)
where side is the side where the disk drive you want to use is.

EDIT: Sorry, I misunderstood - I thought you haven't ever used disk API.

I want it to automatically check for the label.

So, can you get this to work:


if disk.getLabel("top") == "SFTTicket" then
blah blah blah code
end

Idk how to get it to work. It always says "returned nil"

EDIT: GOT IT! THE ERROR WAS WHERE I PUT BLAH BLAH BLAH CODE