Morrowind modding for smarties, part 4: MWEdit, MWSE, MSC, Mash, Notepad++

Due to a powerful enough but "primitive" scripting engine, Morrowind scripting  is one of the most glitchy things in all game, happily crashing in apparently mysterious ways for just a extra or missing formatting space in script source, so having a good script syntax is a very important thing.

The construction set (TESCS) can catch some scripting errors (it is usually good at pointing references to missing or no memory persistent objects), but many of them remain unseen. Luckily we have a couple of great tools to the rescue.
MWEdit is a must, let's see how to use it.

First thing I do after installing it is configuring it, that is, you go to View\Options and set:
Default Author: your name here
Game Data Path: E:\_games\_rpg\Morrowind\Data Files\ (replace this with your full path to Morrowind\Data Files).
Notice that you can work with different Morrowind installations just changing the Game Data Path here.
Strict Object Ids: ON*
Warning Level: Strong*
Indentation: TAB (personal preference)
Initial Indent Level: OFF (personal preference)
Indent Comments More: OFF (same as above)
No Tool Tips: ON (I find them annoying)
Allow Extended Functions: ON*
No Compile Prompt: ON (I find it annoying)
Allow Bloodmoon Features: ON (at least if you don't absolutely need vanilla engine compatibility)
Allow Tribunal Features: ON (same as above)

These are my settings, (*) options are really, really suggested, keep the rest as it suits you.
suggested mwedit settings

Now, let us explain a couple of things. Having no graphics management, MWEdit is very fast if compared to TESCS. Apart from scripting, it can and should be coupled with TESCS for finding objects present in a mod. Its object searching/navigation is usually faster and deeper than TESCS equivalent, and considering that MWEdit does NOT automatically load also the masters of your mod, you can rapidly search and navigate just your mod contents.

Notice that for this reason, when you are trying to edit/save/compile your scripts, you must manually tick also the masters of your mod (Morrowind.esm and any other needed master) in MWEdit load list, they are NOT loaded automatically.

Another great thing is that you can sort the loading mod list clicking on the column headers, so sorting by mod name you can easily find your mod in a still long but alphabetically ordered mod list (much faster than TESCS unordered equivalent). Pay attention to one thing though: the ordering you see is the ordering by which you will load the mods in MWEdit, so pay attention to sort things back to standard ordering by descending date before loading your mod in MWEdit, else you risk to load e. g. Morrowind.esm after your mod and have "unable to find object xx" errors when compiling.

It must be said that MWEdit is marvelous, but still beta, and sometimes I found it can screw some things, so better use it exclusively for scripting or as searching tool.
In other words, my recommendation is:
- freely use MWEdit as mod object search/mod analyze tool
- use MWEdit to check/fix/compile your scripts and save the mod directly from MWEdit if and only if you are using some scripting extender feature so you can't compile your scripts from TESCS.
- If you are using standard Morrowind syntax, use MWEdit as script syntax check, script formatting tool until your scripts can be compiled with no errors under MWEdit strong syntax checking, then copy and paste (or use Mash export/import scripts, more on this later) your scripts to TESCS and compile/save the mod from TESCS.

Also, there are some perfectly legit and useful things that MWEdit does not like (still beta, remember?), typically
- referencing local variables using the . (dot) syntax  e.g.
set myObject.myVariable to 1
- calling the choice function (usually useful in a script to be called from dialog result)
To handle these, just temporarily comment your code/ignore MWEdit ranting until you have fixed the rest of the code.

Another thing to know is that there are some syntax glitches (typically missing spaces and the like) found by MWEdit using "compile active scripts" in strong syntax check mode, but without being able to point to the exact error line AND script name, so in these cases another tool can help: MWSE.

MWSE (Morrowind Scripting Editor, not the script extender using the same acronym) is another good scripting editor. It lacks syntax checking/code compiling capabilities, but it has a good help file and a precious code auto-formatting option able to fix a lot of those missing spaces that MWEdit is not able to surgically find as usual.
So, how to use it? First thing to do is configure it, here are my MWSE settings in View\Syntax Options...
Autoformat: FALSE (important! you want to be the one to choose to format)
Keywordcasing: NoChange (if you prefer to have casing changed automatically, set it accordingly)

Now to take advantage of MWSE auto format, just create a new empty script in MWSE and paste your MWEdit/TESCS script there, then in MWSE choose Edit\Advanced\Format Script (or simply press F5).
You will notice MWSE formatting nicely puts correct spaces when needed.

Ok, you could now slowly copy/paste script(s) between MWEdit, MWSE and TESCS, but "why walk when you can ride?".
Ladies and gentlemen, let me introduce you a very handy feature of Mash: scripts export/import.

Select your mod (e.g. mymod.esp) in Mash, right click and choose Export\Scripts, using this you can save all your mod scripts source in a file somewhere (I put them all in a Morrowind\Scripts folder), I will call it mymod_scripts.mws.

Now you have all your mod scripts together in a text file. If mod is not very simple, I find convenient to work with this file in my preferred text editor (Notepad++), I have also a dedicated Morrowind syntax highlighter so I can have nicely colored Morrowind syntax and especially Morrowind code folding in Notepad++.

Usually search/replaces/compare/format a text file is easier with a good text editor, especially when you have to work with similar (but not identical) Morrowind scripts.

When my changes are ready to test, I import my scripts back to my mod (you have Mash Lock Times on, don't you?),
So, right click the mod in Mash, Import\Scripts... and select your mymod_scripts.mws or whatever you called it.

What next? Time to check for scripting errors. Load your mod (which has fresh script sources inside) AND its masters in MWEdit, set the mod as active, choose Edit\Compile Active Scripts, wait for the error messages window.

Don't instantly close the error window, select all error text, copy it, paste it in a new window in your preferred text editor (Notepad++ or Notepad), you want to keep this information (I will call it "The Error List") to be able to find the errors.

Now, close the error window and try to get the script names from the error message. If you are able to find the bad script name, you are lucky, you can open that script in MWEdit and compile/fix it until all errors are gone. If you are a good scripter or a savvy modder/mod user, you should be able to do it with MWEdit help.

So, assuming you are a good one, iterate (compile/fix the script in MWEdit) until there are no more errors in "The Error List" pointing to a known script.

Often you will remain with some errors not pointing to a explicit script name after Edit\Compile Active Scripts, usually something like "1) Warning: Line x (y): Comparison operator missing space characters on one/both sides!"

Problem is, line x may be ok, but instead of script name MWEdit spits a rather cryptic script index which I still haven't deciphered.

In case this happens, it is often convenient to just create a new empty script in MWSE and paste your entire mymod_scripts.mws source scripts there, then in MWSE choose Edit\Advanced\Format Script. If you are lucky, MWSE formatting may solve a lot of these pesky missing spaces errors.

So, assuming we have our fresh-formatted scripts, we will copy and paste them back to mymod_scripts.mws, then update our mod (right click mod in Mash, Import\Scripts).

Now it is time to reload our mod with its freshly auto-formatted scripts in MWEdit and see if those pesky errors are really gone. When errors are all gone, save the mod from MWEdit with a different name (e.g. mymod_fixed.esp), right click mymod_fixed.esp in Mash, Export\Scripts to mymod_fixed_scripts.mws, right click mymod.esp in Mash. Import\Scripts mymod_fixed_scripts.mws.

So, it is usually something like this:
Mash export scripts-->edit with Notepad++-->Mash import scripts-->test/fix with MWEdit/MWSE->mash export scripts->Mash import scripts
It may seem a daunting procedure, but I assure you that with a bit of practice it becomes familiar, and if your scripts are complicated it will spare you a lot of debugging time and eye straining/headaches trying to find the error line by yourself.


2018 Note/Update: As it seems dot.net framework 1.x support is no more available on Windows versions >= 8, to run MWSE text editor you probably would need a older version of Windows, not really practical.

A pity, time to learn how to search/replace text with regular expressions syntax in e.g. Notepad++ if you want to fix those pesky spaces/brackets.