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.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ Bug reports
➜ OnPluginPlaySound - Possible bug
OnPluginPlaySound - Possible bug
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Kathan
USA (9 posts) Bio
|
Date
| Fri 25 Jul 2014 11:49 PM (UTC) |
Message
| MUSHclient version 4.84
I'm working on a plugin and I wanted to make it so that the sounds would work regardless of the MUSHclient folder's location. After searching the forums I decided to use the OnPluginPlaySound callback.
function OnPluginPlaySound (s)
Sound (GetInfo(57) .. "Sounds\" .. s)
end -- OnPluginPlaySound
I renamed the sounds in the plugin to just the file names and everything worked great. Then I noticed that the sounds in my world triggers were making beeps instead of playing the correct sounds.
After some troubleshooting, I changed the OnPluginPlaySound to print some Notes.
function OnPluginPlaySound (s)
Note (GetInfo(57))
Note (s)
Note (GetInfo(57) .. "Sounds\" .. s)
Sound (GetInfo(57) .. "Sounds\" .. s)
end -- OnPluginPlaySound
I then used Simulate to continue testing sound triggers from outside the plugin and from inside the plugin. To my surprise, the triggers outside the plugin were also being processed by the OnPluginPlaySound function. MUSHclient was simply passing the enitre path of the sound file as 's'.
C:\Program Files (x86)\MUSHclient\worlds\ -- GetInfo(57)
C:\Program Files (x86)\MUSHclient\worlds\Sounds\Mine.wav -- s
C:\Program Files (x86)\MUSHclient\worlds\Sounds\C:\Program Files (x86)\MUSHclient\worlds\Sounds\Mine.wav -- GetInfo(57) .. "Sounds\" .. s
I read the help file for OnPluginPlaySound and I'm honestly not sure if this is intended behavior or not. However, my understanding was that plugins were intended to stand on their own. It doesn't make sense to me that OnPluginPlaySound grabs sounds from outside the plugin where it is called.
If this is intended behavior, maybe we could get a version OnThisPluginPlaySound or something that only grabs internal sounds?
I came up with the following workaround that has solved my problem for now.
function OnPluginPlaySound (s)
b, e = string.find (s, "^%a:\") -- check if s begins with drive letter
if b and e then -- if both are true, then s began with a drive letter
Sound (s) -- so play s without prepending anything to it
else
Sound (GetInfo(57) .. "Sounds\" .. s)
end -- if
end -- OnPluginPlaySound
| Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #1 on Sat 26 Jul 2014 01:11 AM (UTC) |
Message
| Yes that is intended behaviour because in this particular case the OnPluginPlaySound is supposed to be a global replacement for playing sounds (from anywhere).
There are a few similar callbacks, like OnPluginTrace. These are intended to allow you to "drop in" a plugin to catch things that otherwise would have default behaviour.
In these cases it doesn't make sense for the effect to be limited to the plugin in question. Effectively the plugin is providing a "hook" to functionality provided elsewhere.
In the case of OnPluginPlaySound it was intended (as I recall) that it be used to allow you to use PlaySound (rather than Sound) to allow for multiple sounds to be played simultaneously (or overlapping) without changing all the code (including internal code like trigger sounds) that used to previously call the simpler sound functions.
See the release notes for version 3.69:
http://www.gammon.com.au/scripts/showrelnote.php?version=3.69&productid=0
You can make a local handler for the Sound function using a similar technique to what I described here:
http://www.gammon.com.au/forum/?id=12522
local function make_sound_func (f)
return function (s)
if string.match (s, "^%a:\\") then -- see if s began with a drive letter
f (s) -- so play s without prepending anything to it
else
f (GetInfo(66) .. "Sounds\\" .. s)
end -- if
end -- function
end -- make_check_func
-- see if already done
local t = debug.getinfo (Sound, "S")
if t.short_src == "[C]" then -- if not already converted
world.Sound = make_sound_func (Sound)
end -- if
This replaces (in the current script space) the Sound function by one which does the extra checks you wanted. I changed your GetInfo from 57 to 66 for testing. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #2 on Sat 26 Jul 2014 01:12 AM (UTC) |
Message
| Or more simply, just make your own function MySound which has the tests for the filename, and have it call Sound. That might be a bit clearer. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #3 on Sat 26 Jul 2014 01:17 AM (UTC) |
Message
| I should also point out that the default behaviour of Sound is to respect a full pathname, and play that, otherwise it looks inside the MUSHclient "sounds" folder. Thus you shouldn't really need to care where that is, nor should you need to write a function to replicate that check. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Kathan
USA (9 posts) Bio
|
Date
| Reply #4 on Sat 26 Jul 2014 04:45 AM (UTC) |
Message
| Alright, that makes sense. Thanks for the information! | Top |
|
Posted by
| Kathan
USA (9 posts) Bio
|
Date
| Reply #5 on Sat 26 Jul 2014 04:57 AM (UTC) |
Message
| Also I somehow read that help documentation 3 or 4 times with out seeing the line:
Quote: If it finds a plugin with the OnPluginPlaySound function defined, then that is called, and the internal sound-player is not used
I apologize for being blind. | 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.
16,824 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top