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

[1.6.4][CC1.63] audio.HasAudio() returning Title

Started by Jonas_spielt, 13 February 2016 - 05:20 PM
Jonas_spielt #1
Posted 13 February 2016 - 06:20 PM
VERSION:
CC 1.63
DESCRIPTION:
I inserted the music disk C418 - wait into my Disk Drive on the rightern side of my Advanced Computer.
Then I started the lua interpreter with "lua", followed by 'disk.hasAudio("right")'. Then it returned the name/title of the disk: "wait".
EXPECTED RESULT:
It should have returned a boolean value.
REPRODUCTION STEPS:
Place a disk drive on the right side of a Advanced Computer.
Insert music disk C418 - wait.
Then go into your Advanced Computer.
(Start lua interpreter with lua if not creating a new file)
Type ' disk.hasAudio("right") '.
(Save file if created one. Then exit and run the file)
See the result.
SCREENSHOT:
HPWebcamAble #2
Posted 13 February 2016 - 08:54 PM
In CC 1.75, it correctly returns a boolean. I imagine this was fixed some time ago.
Jonas_spielt #3
Posted 13 February 2016 - 10:26 PM
Oh, ok. Didn't test it in other versions.
Thanks for the reply. :)/>
Anavrins #4
Posted 14 February 2016 - 12:23 AM
Why should it return a boolean value,
Sure, it will not work with
if audio.hasAudio() == true then
but you can still make it work with
if audio.hasAudio() then
HPWebcamAble #5
Posted 14 February 2016 - 05:25 AM
Why should it return a boolean value

Well, I guess the main reason is functions like hasThing return a boolean value most of the time.
There is, of course, a way to get the title, with getAudioTitle().

If one of them was removed though, and it simply returned the name of the music disk, that could work too. Apparently Dan choose the current way.
hugebones #6
Posted 14 February 2016 - 04:56 PM
Why should it return a boolean value,
Across all good programming everywhere, any function that has the verbs has, is, can, etc always return booleans.
Mainly because you either have or have not, are or are not, etc…

It's one of those logical things.

Yes, could go for a
if (getAudioTitle() != "")
(provides the same functionality), but
if(hasAudio())
is much neater, easier to read, and easier to understand!