Disk API

Functiondisk.eject
Ejects the disk in the disk drive at drive. This will eject the disk item itself out of the drive and back into the world.
A disk being ejected from a disk drive.
Syntax disk.eject(
  • drive : string The side or network name of the disk drive to eject the disk from.
)
Returns nil
Part of CC:Tweaked (source)
API disk
ExampleEject a disk
Ejects a disk from the drive to the left of the computer.
Code
<nowiki>
disk.eject("left")
    </nowiki>
Functiondisk.getAudioTitle
Returns the title from a music disk in the given disk drive. Returns false, if there is no music disk in the disk drive.
Syntax disk.getAudioTitle(
  • side or network name : string
)
Returns string title
Part of CC:Tweaked (source)
API disk
ExamplePrint title
Print the title of the music disk in the top drive.
Code
print(disk.getAudioTitle("top"))
Output C418 - ward
Functiondisk.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
ExampleGet 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.
Functiondisk.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
ExampleGet 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.
ExampleCheck 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!'
Functiondisk.getMountPath
Returns path where the content of a Floppy Disk is mounted in CraftOS. Returns nil, if there is no Floppy Disk in the given disk drive.
Syntax disk.getMountPath(
  • side or network name : string
)
Returns string path
Part of CC:Tweaked (source)
API disk
ExamplePrint path
Print the mount path of the Floppy Disk in the top drive.
Code
print(disk.getMountPath("top"))
Output disk
Functiondisk.hasAudio
Checks if a disk drive has an item attached, and if that item is a music disk.
Syntax disk.hasAudio(
  • side or network name : string
)
Returns boolean result
Part of CC:Tweaked (source)
API disk
ExampleIs there a music disk?
Check if a music disk is present in the top disk drive.
Code
if disk.hasAudio("top") then
  print("The top disk drive contains a music disk!");
else
  print("There is no music disk present in the top disk drive!");
end
Output If a music disk is present in the top disk drive it says so, otherwise it says there are no music disk present.
Functiondisk.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
ExampleIs 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

Functiondisk.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
ExampleIs 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.
Functiondisk.playAudio
Plays a music disk.
Syntax disk.playAudio(
  • side or network name : string
)
Returns nil
Part of CC:Tweaked (source)
API disk
ExamplePlay music
Play the music disk in the top drive.
Code
disk.playAudio("top")
Functiondisk.setLabel
Set the label of a disk.
Syntax disk.setLabel(
  • side : string
  • label? : string
)
Returns number ID
Part of CC:Tweaked (source)
API disk
ExampleSet disk label
Sets the label of the disk inserted in the disk drive on the top to "Disk123".
Code
disk.setLabel("top", "Disk123")
Functiondisk.stopAudio
Stop playing of a music disk which was started with disk.playAudio.
Syntax disk.stopAudio(
  • side or network name : string
)
Returns nil
Part of CC:Tweaked (source)
API disk
ExampleStop playing
Stop playing audio from disk in the top drive.
Code
disk.stopAudio("top")
This article is issued from Computercraft. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.