Looking in the wrong directory.

Posted by Daved on Wed 08 Dec 2010 03:08 AM — 11 posts, 39,815 views.

#0
So for over a year now I've had this filepath in the Start in: field on my MUSHClient shortcut:

"C:\Users\David Volin\Documents\Aetolia\AMTS"

It's been working perfectly. Today, I started working on a new module. As soon as I went to require said module, this happened:

Run-time error
World: AMTS
Immediate execution
.\main.lua:13: module 'queue' not found:
no field package.preload['queue']
no file '.\queue.lua'
no file 'C:\Program Files\MUSHclient\lua\queue.lua'
no file 'C:\Program Files\MUSHclient\lua\queue\init.lua'
no file 'C:\Program Files\MUSHclient\queue.lua'
no file 'C:\Program Files\MUSHclient\queue\init.lua'

Why did it suddenly start looking in the wrong directory on me? The filepath in Start in: is still the same
#1
There is probably an easier solution, but I use the following two lines at the top of each main script file:


Dir, _ =  string.gsub (GetInfo (35),"[%a_]+%.lua","")
package.path = package.path .. ";" .. Dir .. "?.lua"


It adds the directory that my script file resides in to the search path, which may be different that the directory MushClient is starting in.

Of course it requires that I put the files I want to require in the main script file's directory.
#2
Do I just add that to the top of the file I see when I enter the scripts menu?
#3
Yes.

If you use anything in your script file name except letters and the underscore then the pattern, "[%a_]+ will need to be modified.
USA #4
You should be fine with [%d_ ]+. It just allows for digits and spaces too.
#5
I put

Dir, _ = string.gsub (GetInfo (35),"[%d_]+%.lua","")
package.path = package.path .. ";" .. Dir .. "?.lua"

and got this error now:

no file 'C:\Users\David Volin\Documents\Aetolia\AMTS\Aevon.luaqueue.lua'

The main script file is called Aevon.lua and it is at

'C:\Users\David Volin\Documents\Aetolia\AMTS\Aevon.lua'

looks like it just concatenated queue.lua to its name, queue.lua is at
'C:\Users\David Volin\Documents\Aetolia\AMTS\queue.lua'
#6
That should be [%a_]+. What it's doing is getting rid of the filename so you just have the path. [%d_]+ would only remove something like 3_45678.lua. I'm leaving off the rest of the pattern there... the full pattern has %.lua attached.

Sorry if I confused you earlier.
#7
You may want to look at the output of GetInfo(35) so you can see what you are trying to do.

On my muds, I use / to denote a script command on the command line so I would enter /Note(GetInfo(35)) at the command line.

All we are trying to do is to remove the last bit of the path so we only have the directory, then add that direction to our 'search path'.
#8
If your script file name also has spaces and/or digits, then
just use [%w%s_]+. '%w' is alphanumeric (letters and digits), %s is spaces, and the _ underscore.
#9
Got it, works now, thank you :)
USA #10
Yeah, oops, that was my fault. I meant %w, as you can tell by my original explanation. %d only matches digits.