Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.
 Entire forum ➜ MUSHclient ➜ Lua ➜ Playing Sounds

Playing Sounds

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Sickent   USA  (12 posts)  Bio
Date Fri 16 Apr 2021 11:32 AM (UTC)
Message
I think I'm doing something dumb, but please mercy. I'm trying to get a sound to play through a script and I'm getting nil in return.

I have test.wav in ~/sounds/.

If I make a script.lua, and only put

Sound ("test.wav")

Into it, when I load the script, nothing happens and nothing is played.

Trying

require "check"
Note (check (Sound ("test.wav")))

Just gives me a blank line, no eOk or error.

I'm not sure if it matters, but I can make an alias to play the sound and MUSHClient plays the sound just fine. Assuming the .wav was created correctly, I'm super confused why I'm not at least getting some kind of confirmation out of check or sound in general.

Thank you.
Top

Posted by Nick Gammon   Australia  (23,101 posts)  Bio   Forum Administrator
Date Reply #1 on Fri 16 Apr 2021 10:05 PM (UTC)
Message
Try doing:


print (GetInfo (74))


That should tell you your default sounds directory.

Also try:


print (check (PlaySound (1, "test.wav")))


I found that Sound did not give an error, whereas PlaySound did, if the file wasn't there.




Test your script (that is, the PlaySound line) by using the Immediate window (Ctrl+I) so there isn't any doubt that there is not some other problem with the scripting.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,101 posts)  Bio   Forum Administrator
Date Reply #2 on Fri 16 Apr 2021 10:17 PM (UTC)

Amended on Fri 16 Apr 2021 10:20 PM (UTC) by Nick Gammon

Message
After searching through the source I found an interesting thing. Sound uses the Windows API call PlaySound to play .wav files, and the documentation for PlaySound says:

Quote:

If it cannot find the specified sound, PlaySound uses the default system event sound entry instead. If the function can find neither the system default entry nor the default sound, it makes no sound and returns FALSE.


Thus, if the file isn't found it plays the default beep (which I was hearing) and returns an OK return, so you get no error message.

However, the MUSHclient script function PlaySound (confusingly, the same name as the API function) plays sounds a different way, and thus returns "file not found" if it can't find the file. This different way allows for multiple sounds at once, volume changes, panning etc.

Thus I think your problem is that the file isn't found, most likely because the sound file isn't in the default directory.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,101 posts)  Bio   Forum Administrator
Date Reply #3 on Fri 16 Apr 2021 10:19 PM (UTC)
Message
Sickent said:

Trying

require "check"
Note (check (Sound ("test.wav")))

Just gives me a blank line, no eOk or error.


The design for "check" is that it doesn't return an error message for eOk, otherwise you would be getting a confusing "No error" message every time you did a check. You may have seen such stuff with Windows at times: "You have got an error: No error".

If you omitted "check" from that line it would have printed 0.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Sickent   USA  (12 posts)  Bio
Date Reply #4 on Fri 16 Apr 2021 10:32 PM (UTC)
Message
Nick Gammon said:
If it cannot find the specified sound, PlaySound uses the default system event sound entry instead. If the function can find neither the system default entry nor the default sound, it makes no sound and returns FALSE.

This explains a lot, and I did something dumb with the file structure. You're right. Thank you for the help.
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


11,308 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.