MUSHClient giving error when loading plugin on startup

Posted by Hadoryu on Tue 22 Sep 2009 07:48 AM — 6 posts, 27,030 views.

#0
Hello,

I've been using MUSHClient for a few years now and doing some scripting on it. I started recently on a Plugin that should be easily distributable/installable, but I've run into a small problem that I'm not sure how to address.

The plugin, when loaded, works fine. However, when you shut MUSH down and then start it up again and open the world that the plugin was installed in, it fails to load, giving two error messages:

Line 1012: Error processing include file "C:\Program Files\MUSHclient\worlds\plugins\Hadoryu Plugins\STP\StarterPack.xml" (include file not loaded)

^ this is from the .MCL

Line 1249: Error parsing script (problem in this file)

^ this is from the .XML of the plugin.

All I can see under Line 1249 is the opening of a script block. I've tried to figure out if there isn't an error there, but the plugin has no problems if I just load it up manually.

This is the plugin itself:

http://hadoryu.uuuq.com/starter_pack/STP.zip

It's looking to me like a bug, but I'm not sure.

Any ideas?
Australia Forum Administrator #1
Template:version
Please help us by advising the version of MUSHclient you are using. Use the Help menu -> About MUSHclient.
#2
Sorry, I forgot to mention it. The problem initially came up with version 4.40. I then upgraded to 4.43 to test if that would fix it, but the result was the same.
Netherlands #3
I am trying to reproduce your problem with the steps you described. To make sure I did so correctly, here's what I did and do on my way to fixing stuff.

1) Create a new world.
2) Save it as C:\Projects\Test.mcl
3) Extract your plugin to C:\Projects\tmp\
4) Load the plugin.
5) Save & close MUSHclient.
6) Restart MUSHclient. Load Test.mcl.
7) Errors I encountered were different from yours:

Scripting error popup:
[string "Plugin"]:638: attempt to call local 'f' (a nil value)
stack traceback:
	[string "Plugin"]:638: in function 'loadAfflictionColors'
	[string "Plugin"]:798: in main chunk

Starterpack.xml Notepad window:
Line 1249: Error parsing script (problem in this file)

Test.mcl:
Line  422: Error processing include file "C:\Projects\tmp\StarterPack.xml" (include file not loaded)


8) I found the following code: (do NOT forget that any <include> directives bump the line numbers - in this case, you are being confused with the line numbers by your constants.lua include!)
function loadAfflictionColors()
	SysNote("Loading Affliction colors from : "..AFFLICTION_COLORS_FILE)
	local f = loadfile(AFFLICTION_COLORS_FILE)
	f()
	return true
end


The error here is that you use loadfile(), yet do not check if it succeeded. I suggest you adjust it as follows to make debugging more easier:

function loadAfflictionColors()
	SysNote("Loading Affliction colors from : "..AFFLICTION_COLORS_FILE)
	local f = loadfile(AFFLICTION_COLORS_FILE)
	if (f ~= nil) then
		f()
		return true
	else
		Note("Could not load "..AFFLICTION_COLORS_FILE)
		return false
	end
end


9) Why could it not load the file? Simple, because it couldn't FIND the file. Looking at the definitions, we find:
AFFLICTION_TRIGGERS_FILE = "STP_triggers.lua"
AFFLICTION_CURE_TRIGGERS_FILE = "STP_cures.lua"
AFFLICTION_DIAGNOSIS_TRIGGERS_FILE = "STP_diagnosis.lua"
AFFLICTION_COLORS_FILE = "STP_affliction_colors.lua"
CURE_COLORS_FILE = "STP_cure_colors.lua"
EAT_AFFLICTION_PRIORITIES_FILE = "STP_eat_affliction_priorities.lua"
APPLY_AFFLICTION_PRIORITIES_FILE = "STP_apply_affliction_priorities.lua"
DRUG_AFFLICTION_PRIORITIES_FILE = "STP_drug_affliction_priorities.lua"
AUTOSIPPER_FILE = "STP_autosipper.lua"

at the top of your file. Suggested fix is as follows:
PLUGIN_PATH = GetPluginInfo(GetPluginID(), 20)

AFFLICTION_TRIGGERS_FILE = PLUGIN_PATH.."STP_triggers.lua"
AFFLICTION_CURE_TRIGGERS_FILE = PLUGIN_PATH.."STP_cures.lua"
AFFLICTION_DIAGNOSIS_TRIGGERS_FILE = PLUGIN_PATH.."STP_diagnosis.lua"
AFFLICTION_COLORS_FILE = PLUGIN_PATH.."STP_affliction_colors.lua"
CURE_COLORS_FILE = PLUGIN_PATH.."STP_cure_colors.lua"
EAT_AFFLICTION_PRIORITIES_FILE = PLUGIN_PATH.."STP_eat_affliction_priorities.lua"
APPLY_AFFLICTION_PRIORITIES_FILE = PLUGIN_PATH.."STP_apply_affliction_priorities.lua"
DRUG_AFFLICTION_PRIORITIES_FILE = PLUGIN_PATH.."STP_drug_affliction_priorities.lua"
AUTOSIPPER_FILE = PLUGIN_PATH.."STP_autosipper.lua"


10) Save the changes. Repeat steps 5) and 6).
11) No more errors.

Edit: Right, forgot the conclusion/summary thing.

The problem here, as always with MUSHclient plugins that won't load after restarting, is that they tend to depend on the current working directory. Depending on the users last open or save action, that can differ. In your case, your MCL was in another directory, and since it was most recently browsed in by the user, that is where the current directory pointed at - not the directory of your plugin.

The lesson here is to always make sure you feed MUSHclient absolute pathnames, even if you have to take a little bit more trouble in finding out what that path would be.
Amended on Tue 22 Sep 2009 03:23 PM by Worstje
Australia Forum Administrator #4
Very detailed explanation, Worstje. :-)


Worstje said:

The error here is that you use loadfile(), yet do not check if it succeeded.


The function 'dofile' is designed to do exactly that. It loads the file, checks for errors, and then executes the loaded function:

http://www.gammon.com.au/scripts/doc.php?lua=dofile

I agree with your other comments. Anything that relies upon the "current directory" is likely to fail from time to time, unless you can absolutely be sure what the current directory is.
Amended on Wed 23 Sep 2009 01:22 AM by Nick Gammon
#5
That worked, thank you!

Sorry for the late reply. And yes, the error message ended up confusing me more than helping, I think. Will keep it in mind in the future.