ensuring working directory

Posted by Tspivey on Sat 01 Jul 2006 08:12 PM — 5 posts, 24,080 views.

Canada #0
How can I ensure that mushclient always gets its sounds from one directory, i. e. worlds\gw2 from the mushclient main directory? I want to send my world file to someone else, and even for my own use, I want to use something like:
Sound("swings/8.wav")
but without specifying a path name. Running os.execute("cmd") shows that my working directory goes from documents and settings upon world open, to the mushclient plugins directory, etc. Any way to keep it in the mushclient.exe program directory?
Australia #1
You can use GetInfo [ http://www.gammon.com.au/scripts/function.php?name=GetInfo ] to return various directories.

For a folder of sound files in the world directory, the path (in Lua) would be,
GetInfo(57).."soundfolder\soundfile.wav"
, that is probably about as generic as it can get? If you put that in a Note, something like c:\mushclient\worlds\soundfolder\soundfile.wav would be printed.

I see that the shortcut for MUSHclient that the installer put in the start menu has its "Start in" box set to "C:\Documents and Settings\myusername\Start Menu\Programs\MUSHclient". This should be easy enough to change to your mushclient directory, or maybe you can leave it empty? I don't really understand what it is for, as other shortcuts sometimes have nothing and each works fine :). Anyway, with using the GetInfo, the actual working directory shouldn't matter?
Canada #2
That would work fine, except in the browse for sound dialog. I want to send my world file to someone else, but have everything off the mushclient directory, no matter what it's called. I can't write GetInfo(57) in the sound browse dialog, and having everything send to script is rather annoying to set up. I'm thinking that Mushclient should put itself in the directory containing the .exe, and stay there.
Australia #3
In your OnWorldOpen, could put this to modify any sound attributes.
for k,v in pairs(GetTriggerList()) do
	sound_dir = sound_dir or "sounds"
	-- check if directory is in the right place and if the trigger has a sound file
	if not string.find(GetTriggerOption(v,"sound"),GetInfo(57)) and not GetTriggerOption(v,"sound")=="" then
		-- patch up the sound attribute of trigger with incorrect path
		SetTriggerOption(v,"sound",string.gsub(GetTriggerOption(v,"sound"),"^.+\\"..sound_dir.."\\(.+)",GetInfo(57)..sound_dir.."\\%1",1)
	end
end


Modify the actual directories as you like :). The sound file paths are stored as absolute paths, so I see little option other than to use scripting.

You would still be able to pick sounds as normal, and the first time someone else runs your files, the paths should be changed automatically.
Amended on Mon 03 Jul 2006 03:23 AM by Cino
Australia Forum Administrator #4
See:

http://www.gammon.com.au/scripts/doc.php?general=plugin_callbacks

Just make a plugin callback OnPluginPlaySound. In that you can prepend a pathname (or check if one is there) and then call Sound to play the resulting path.

eg.


function OnPluginPlaySound (s)
  Sound ("some_directory\\" .. s)
end -- OnPluginPlaySound