Advertisement
Guest User

rnd

a guest
Jun 19th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.69 KB | None | 0 0
  1. lengths = {["C418 - 13"]=180, ["C418 - cat"]=186, ["C418 - blocks"]=347, ["C418 - chirp"]=186, ["C418 - far"]=172, ["C418 - mall"]=197, ["C418 - mellohi"]=98, ["C418 - stal"]=151, ["C418 - strad"]=191, ["C418 - ward"]=250, ["C418 - 11"]=70}
  2. --config
  3. local side = "right"
  4. local ejectOutput = "bottom"
  5. local insertOutput = "left"
  6.  
  7. function clear()
  8.   term.clear()
  9.   term.setCursorPos(1,1)
  10. end
  11.  
  12.  
  13. --show name and time left while playing
  14. function show(name, length, endTime)
  15.   clear()
  16.   print("Playing: ", name)
  17.   local untilEnd = math.floor(endTime - os.clock())
  18.   print("Time left: ", untilEnd, " seconds")
  19. end
  20.  
  21. --start change function
  22. function change()
  23.     print("inserting new random music disc..")
  24.     --to eject music disc from disk drive
  25.     redstone.setOutput(ejectOutput, true)
  26.     sleep(1)
  27.     redstone.setOutput(ejectOutput, false)
  28.     while disk.isPresent(side) do
  29.         clear()
  30.         print("waiting for auto-eject..")
  31.         sleep(1)
  32.     end
  33.            
  34.     --to insert music disc to disk drive
  35.     redstone.setOutput(insertOutput, true)
  36.     sleep(1)
  37.     redstone.setOutput(insertOutput, false)
  38.     while disk.isPresent(side) do
  39.         clear()
  40.         print("waiting for disc..")
  41.         sleep(1)
  42.     end
  43.     return
  44. end
  45.  
  46. -- start work function
  47. function work()
  48.   if disk.isPresent(side) then
  49.     if disk.hasAudio(side) then
  50.    
  51.       local diskName = disk.getLabel(side)
  52.       local diskLength = lengths[diskName]
  53.       local timer = os.startTimer(diskLength)
  54.       local endTime = os.clock() + diskLength
  55.       show(diskName,diskLength,endTime)
  56.       --start playing
  57.       disk.playAudio(side)
  58.       local tick = os.startTimer(1)
  59.       while true do
  60.      
  61.         local evt, arg = os.pullEvent()
  62.        
  63.         if evt == "disk_eject" then
  64.           print("disk was ejected")
  65.           error("bye")
  66.         end
  67.      
  68.         if evt == "timer" then
  69.           if arg == timer then
  70.             change()
  71.             return
  72.           end
  73.           --end if arg timer
  74.          
  75.         end
  76.         --end if evt timer
  77.        
  78.         if evt == "timer" then
  79.           if arg == tick then
  80.             show(diskName,diskLength,endTime)
  81.             tick = os.startTimer(1)
  82.           end
  83.         end
  84.         --end if evt tick  
  85.        
  86.         if evt == "key" then
  87.           if arg == keys.right then
  88.              change()
  89.              return
  90.           end
  91.         end          
  92.       end
  93.       --end while    
  94.    
  95.     else
  96.     --else for disk.hasAudio()
  97.       clear()
  98.       print("this is not a music disc")
  99.       sleep(1)
  100.     end
  101.   else
  102.     --else for disk.isPresent()
  103.     clear()
  104.     print("nothing in disk drive")
  105.     sleep(1)
  106.   end
  107. end
  108. --end work function
  109. while true do
  110.     work()
  111. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement