Difference between revisions of "Disk (event)"

From ComputerCraft Wiki
Jump to: navigation, search
(Created event page.)
 
(Added example.)
Line 5: Line 5:
 
|desc=Fired when a disk is inserted into any connected (directly adjacent to) disk drive.
 
|desc=Fired when a disk is inserted into any connected (directly adjacent to) disk drive.
 
|return1=The [[String_(type)|String]] value of the side of the disk drive.
 
|return1=The [[String_(type)|String]] value of the side of the disk drive.
 +
}}
 +
{{Example
 +
|desc=Play any music disk put into a connected disk drive, and print the title.
 +
|code=
 +
while true do
 +
  event, side = os.pullEvent("disk")
 +
  if disk.hasAudio(side) then
 +
    disk.playAudio(side)
 +
    print("Playing music disk: ", disk.getAudioTitle(side))
 +
  end
 +
end
 +
|output=The title of any music disk put into a connected disk drive.
 
}}
 
}}

Revision as of 03:41, 28 March 2013

This page needs some serious TLC, stat!
Please help us by cleaning it, fixing it up, or sparing it some love.
(Reason: A demonstration on the use and handling of this event would be beneficial. AfterLifeLochie 16:13, 30 November 2012 (MSK))



Grid Modem.png  Event disk
Fired when a disk is inserted into any connected (directly adjacent to) disk drive.
Returned Object 1 The String value of the side of the disk drive.


Grid paper.png  Example
Play any music disk put into a connected disk drive, and print the title.
Code
while true do
  event, side = os.pullEvent("disk")
  if disk.hasAudio(side) then
    disk.playAudio(side)
    print("Playing music disk: ", disk.getAudioTitle(side))
  end
end
Output The title of any music disk put into a connected disk drive.