Any help is greatly appreciated -HDR <3
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
disk.stopAudio
Started by HDR, 22 January 2016 - 03:31 AMPosted 22 January 2016 - 04:31 AM
Currently setting up a music system, and since turtles are banned on the server i use disk drives hooked up with wired modems, i want the stop button to stop all the music from all the drives, and i'm wondering if i can stop all of them at once using "disk.stopAudio"? i currently got "disk_0 to disk_17"
Any help is greatly appreciated -HDR <3
Any help is greatly appreciated -HDR <3
Posted 22 January 2016 - 05:54 AM
You would need to call it for each individual drive, which wouldn't be too hard. You could do something like this:
for i = 0, 17 do
disk.stopAudio("disk_"..i)
end
Posted 22 January 2016 - 06:29 AM
works perfectly, awesome thanks.You would need to call it for each individual drive, which wouldn't be too hard. You could do something like this:for i = 0, 17 do disk.stopAudio("disk_"..i) end
Posted 22 January 2016 - 09:04 AM
A tip if you hadn't had all the drives in order like this you could use peripheral.getNames to get all the peripherals connected, and then use peripheral.getType to get the type of the peripheral.…
This way you could set it up so that it automatically finds all drives and stops the audio.
Example
for _, name in ipairs( peripheral.getNames() ) do
if peripheral.getType( name ) == "drive" then
disk.stopAudio( name )
end
end
Note that I haven't had a chance to test this since I typed it on my phonePosted 22 January 2016 - 11:11 AM
You can also use peripheral.find() in a similar manner:
peripheral.find("drive", function(name) disk.stopAudio( name ) end)
Posted 22 January 2016 - 07:54 PM
You can also use peripheral.find() in a similar manner:peripheral.find("drive", function(name) disk.stopAudio( name ) end)
Better:
peripheral.find("drive", function(name) return disk.stopAudio( name ) end)
Really better:
peripheral.find("drive", disk.stopAudio)
:D/>
Edited on 22 January 2016 - 06:54 PM
Posted 22 January 2016 - 10:14 PM
You can also use peripheral.find() in a similar manner:peripheral.find("drive", function(name) disk.stopAudio( name ) end)
Better:peripheral.find("drive", function(name) return disk.stopAudio( name ) end)
Really better:peripheral.find("drive", disk.stopAudio)
:D/>
ended up using peripheral.find("drive", disk.stopAudio) since it required a lot less code. thanks
Posted 23 January 2016 - 01:02 AM
Better: … Really better:
Beats me why you'd want to stick a "return" in your first sample, but your second line is indeed more compact than either. :)/>
Posted 19 February 2016 - 11:00 PM
Better: … Really better:
Beats me why you'd want to stick a "return" in your first sample, but your second line is indeed more compact than either. :)/>
When you put a return for the disk.stopAudio(name), then you increase the preformance. (Here not really ;)/> ) (http://www.lua.org/pil/6.3.html)
Edited on 19 February 2016 - 10:03 PM