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

Automatic Music Box

Started by N3MESiS_L3GEND, 12 May 2013 - 10:53 AM
N3MESiS_L3GEND #1
Posted 12 May 2013 - 12:53 PM
Me and my friend are trying to create an automatic music box using the computer, the disks and disk drives. We've connected Networking Cable to the computer which then links to Disk Drives. We have it all working, we tested the command "dj play drive_15" and it played drive 15 so its connected. In the code, We want it so that when you type in whichever song you want to hear it plays the selected disk drive (Typing in "stal" will play the disk drive with the stal disk in it) but the problem is that in the code we arent sure what to type to get dj to play the selected disk drive. We've reached:

if pass == (stal) then

We are not sure what to put after this. it's probably really simple but we dont know and would really appreciate help.

Thanks :)/>
Lyqyd #2
Posted 12 May 2013 - 05:03 PM
Split into new topic.
H4X0RZ #3
Posted 12 May 2013 - 05:28 PM
So, you want to run the dj program in your program?

If yes, try this:

StalPass = "123"
write("Password:")
Pass = read("*")
if Pass == (StalPass) then
shell.run("dj", "play", "<name of your diskdrive where stal is in>")
end

EDIT:
Sorry, I've read your thread again. My snippet doesn't fit.

If there is nobody who can give youan example, I will post it later (I think 2:00pm)
Bubba #4
Posted 12 May 2013 - 09:59 PM
I would go about it like this:
  • Store the name of the drives in a table with the name of the song as the key and the wrapped peripheral as the value. For example:

local song_list = {
  ["stal"] = peripheral.wrap("drive_15");
  ["cat"] = peripheral.wrap("drive_14");
}
  • Whenever the user requests a song be played, check if it exists in the song_list and play it if it does:

local input = read()
if song_list[input] then
  return song_list[input].playAudio()
else
  print("That song does not exist!")
end


For more on peripherals, see here: http://www.computercraft.info/wiki/Peripheral.wrap
For more on the Disk Drive API, see here: http://www.computercraft.info/wiki/Disk_(API)
For more on tables, see here: http://www.lua.org/pil/2.5.html