[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Playing Sounds

Playing Sounds

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


Posted by Sickent   USA  (10 posts)  [Biography] 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.
[Go to top] top

Posted by Nick Gammon   Australia  (22,966 posts)  [Biography] 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
[Go to top] top

Posted by Nick Gammon   Australia  (22,966 posts)  [Biography] 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
[Go to top] top

Posted by Nick Gammon   Australia  (22,966 posts)  [Biography] 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
[Go to top] top

Posted by Sickent   USA  (10 posts)  [Biography] 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.
[Go to top] 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.


9,411 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]