Disk API

From ComputerCraft
Jump to: navigation, search
FunctionFunctiondisk.eject
Ejects the disk in the disk drive at drive.
Syntax disk.eject()
Returns nil
Part of CC:Tweaked (source)
API disk
ExampleExampleEject a disk
Ejects a disk from the drive to the left of the computer.
Code
disk.eject("left")

Disk.getAudioTitle

FunctionFunctiondisk.getID
Returns the ID of the disk drive attached at the specified side or network name. Returns nil if there is no disk drive attached at the specified side or network name or there is no disk in the disk drive.
Syntax disk.getID(
  • side or network name : string
)
Returns number ID
Part of CC:Tweaked (source)
API disk
ExampleExampleGet disk ID
Gets and prints the ID of the disk inserted in the disk drive on the top.
Code
print(disk.getID("top"))
Output If a disk drive is attached on the top, it would return the disk's ID.


FunctionFunctiondisk.getLabel
Returns the label of the disk inside the disk drive at the specified side or network name. Returns nil when no peripheral is attached at the specified side or network name or there is no disk inside the disk drive.
Syntax disk.getLabel(
  • side or network name : string
)
Returns string label
Part of CC:Tweaked (source)
API disk
ExampleExampleGet disk label
Gets and prints the label of the disk inside the disk drive attached to the top side.
Code
print(disk.getLabel("top"))
Output If a disk drive was attached and a disk was inside, the output would be the label of the disk.
ExampleExampleCheck disk label
Checks whether the label of the disk inside the disk drive attached on the top side is a specified label, and then prints the result.
Code
local label = disk.getLabel("top")
if label == "Testing" then
  print("Valid disk!")
else
  print("Invalid disk.")
end
Output If a disk drive was attached, a disk was inside and also the disk label was 'Testing', then it would return 'Valid disk!'

Disk.getMountPath Disk.hasAudio

FunctionFunctiondisk.hasData
Checks if a disk drive has an item attached, and if that item is a floppy disk.
Syntax disk.hasData(
  • side or network name : string
)
Returns boolean result
Part of CC:Tweaked (source)
API disk
ExampleExampleIs there a disk?
Check if a floppy disk is present in the top disk drive.
Code
if disk.hasData("top") then
  print("The top disk drive contains a floppy disk!");
else
  print("There is no floppy disk present in the top disk drive!");
end
Output If a floppy disk is present in the top disk drive it says so, otherwise it says there are no floppy disks present.

Disk.isDrive

FunctionFunctiondisk.isPresent
Checks if an item is inside of a disk drive at the specified side or network name. Returns true if an item is inside the disk drive or false if an item isn't inside the disk drive.
Syntax disk.isPresent(
  • side or network name : string
)
Returns boolean result
Part of CC:Tweaked (source)
API disk
ExampleExampleIs there an item?
Gets and prints whether an item is in the disk drive on the top side.
Code
print(disk.isPresent("top"))
Output If an item was attached to the top drive it'd output true, otherwise it would output false.

Disk.playAudio Disk.setLabel Disk.stopAudio