Morrowind modding for smarties, part 5: dialog editing/fixing

 Dialog/dialogue creating/editing is often a skill that most modders practice before even attempting scripting.

There are several reasons behind this:
- scripting is often considered more difficult/intimidating by people without programming/scripting background.
- while dialogues are usually essential to develop a story/interact with NPCs, scripting is usually not as essential.
Despite the fact that there are probably more dialogue-savvy modders than script-savvy modders around, not everybody seems to be aware of potential issues/existing tools to ease dialog development/fixing.
 
Let's start with a short introduction on possible/frequent dialog pitfalls.
I'm assuming you already know dialog basics here (e.g. dialog infos are filtered by condition, first found entry respecting filter condition wins and such).
 
Dialog entries are stored in a doubly-linked list. Our topic info is linked to previous info id and next info id, e.g., where 0 means "linked to nothing"
 
prev: 0 | info 1 | next: 5
prev: 1 | info 5 | next: 3
prev: 5 | info 3 | next: 0
 
Notice that there is not a defined ordering for topic info indexes, e. g. info with id 5 can be before info with id 3.
 
When working with dialogue most frequent operation is inserting new text info. We can do this essentially in 2 ways:
- we can insert a new blank info and then fill/modify it as needed
- we can copy a existing info and change the copied info to suit our needs.
 
The second way is often convenient, because it can spare you some work when you have to replicate similar things.
Problem is, it is easy (they are identical after all, isn't it?) to mistakenly edit the original topic instead of the copied one, leading to potential dialog problems (see illuminating posts by Jog quoted here).
 
so, here is in short suggested practice when inserting a new dialog topic info:
- try to insert it in the middle (not at the top, not at the bottom) of similar topics pre-existing in the original game
- copy a pre-existing similar topic info, but be sure to modify the pre-selected (with blue background) new info copy created by the Construction Set, NOT the original, unselected topic info right below!
- avoid moving infos up/down with the arrow keys if possible.
 
Having said that, what tools can help us writing correct dialog and/or fixing it?
Let's start from the construction set (TESCS) itself.
 
You know a useful and really powerful feature of dialogue info editing window is the Result field.
You can enter script commands there, with the difference that script commands entered there are not pre-compiled as standard scripts, but interpreted on-the-fly at runtime.

Differently from standard scripts, when you save your dialog info entry, the Result window script code is not pre-compiled/checked for possible errors.

This means that it is very easy to write something wrong without realizing your typos, also because differently from a standard script, scripting errors in dialog Result fields often do not generate error messages even at run-time (bad commands are often simply skipped) so you risk to never realize your errors (misspelled variable/item names, commands assigned to inexistent objects...)
 
Luckily, TESCS dialogue window has a handy "Error Check Results" button that can force scripting syntax check of dialog results entries, sparing you a lot of possible headaches.

There's just one thing to be aware: the button may mess with internal variables states, so NEVER SAVE your mod after having pressed that button, instead use it to check/take note of your result dialog scripting errors, but reload your mod in TESCS before starting fixing things. Or (probably better) look at the whole error messages in the generated Warnings.txt file.
 
Also, as discovered by Rot,
Error Check Results will wrongly report errors for any local variables inside operations ( + - * ...) or IF blocks if they're implicit (without an explicit speaker target, as in speaker.localvariable)".

Dialogue results are scripts but they're not pre-compiled by the CS, so they will behave differently when giving explicit targets ("targetID"-> instead of implicitly targeting the speaker). Compiled scripts can only target an explicit ID if an instance of that ID has been placed in the CS and they can only target the first instance that existed (if a NPC is killed and resurrected, the living NPC no longer counts as the first instance). Dialogue results do not have this limitation, but Error Check Results will report errors if no instance exists.

so e.g.
set state to ( state + 1 )
may be reported as error/warning/false alarm
set state to ( fargoth.state + 1 )
may probably not, but first one will probably work fine

See also the excellent posts by Rot at TR site:
CS pitfalls and tips
how to playtest quests

So, my suggestion is: always use the "Error Check Results" button, but do it with a grain of salt.

Anyway, even Bethesda introduced some dialog result errors, so typically clicking the "Error Check Results" button you will see error warning for the MS_MatchMakeFons topic when loading Tribunal and for the Co_Stock dialog topic when loading Bloodmoon, so if only these errors appear your mod should be OK. 
 
You would be surprised by how many errors you can find clicking that button even in well-known mods, a clear sign this feature is often unknown/underestimated.
 
In any case, if you have run-time only errors when doing dialog commands like startcombat player (especially if you have a long/heavy loading list), often things can be fixed delaying the problematic command until out of menu/dialog mode.

A simple way to do this is putting the command out of the dialog result and into a new global targeted script, so in dialog result e.g. instead of:
startcombat player
goodbye

try putting goodbye first e.g. something like:

goodbye
startcombat player


, and if it still does not work use something like

startscript myDialog1script
goodbye


where myDialog1script is e.g.

begin myDialog1script

if ( MenuMode )
  return ; return until out of menumode
endif

startcombat player
stopscript myDialog1script

end

 

Another thing that would often be useful when dealing with dialogue is exporting/importing dialogue to other tools more suitable for text editing/fixing (think about spell checking, text replacements...).

TESCS provides such a tool with the File\Export Data\Dialogue\New Dialogue menu command and related File\Import Data\Dialogue.

N.B. before using the dialog export/import feature of TESCS, be sure to have the
MaintainImportedDialogueOrder=1
option set under [General] section of your Morrowind.ini file, else your dialogue will load in reverse order from export/import.
 
The TESCS exported dialog data though, while comprehensive, is exported in tab-separated like format, which is more suitable for spreadsheet-like editing than for pure-text editing.
 
Also, it has problems with line breaks in long text topic info: when exporting line breaks are converted to [CRLF], so text is expanded and the final part of your long (about 511 character or more) text can be cut.
Sometimes [CRLF] is not converted back to line breaks correctly when importing.

So, try to avoid formatting your topic info using line breaks and keep it shorter than 500 characters if possible.

There are other tools that can export/import using a format more suitable for text editing.
 
If
  • you are not using dialog result field
  • your dialog info is shorter than 512 characters
  • you are not using line breaks to format dialog info
 
Else you can try ESparser (install ESParser v1.2.147 first, then update to v 1.3Beta as the 1.3beta may be missing a dll included in previous version).

ESparser
 is a useful tool not only for dialog spell checking and NPC lists making, but especially for its on-the fly topic changing and dialog export/import options.

The exception is: I've sadly found ESParser being a possible culprit of the creature sound bug problem, so always check in TESCS your mod size/content and sound gen after saving from ESParser.
 

There is also another thing you should pay attention to: as dialog exported by ESparser uses " as text delimiter, " are doubled (e.g. " is replaced by "") inside dialog text to avoid ambiguity so be sure to not mistakenly change them when you are spell-checking using your preferred text editor.

So a possible workflow could be:

  1. create/edit dialog in TESCS, save your mod (e.g. as my_mod.esp)
  2. open your mod with ESparser, export the dialog to mymod_esparser.txt or some other file name
  3. edit/fix/spellcheck/replace textual dialog with your preferred text editor (e.g. NotePad++ , Everedit...), save back to mymod_esparser.txt
  4. import edited text back in ESparser, save as... the mod using a different name (e.g. fixed_dialog.esp)
  5. verify you have the
    MaintainImportedDialogueOrder=1
    option set under [General] section of your Morrowind.ini file, else your dialogue may load in reverse order from TESCS export/import dialog
  6. open fixed_dialog.esp in TESCS, delete file fixed_dialog.txt if already present (because export appends to file), File\Export Data\Dialogue\New Dialogue to fixed_dialog.txt
  7. open my_mod.esp in TESCS, File\import Data\Dialogue from fixed_dialog.txt, save

Remember that ESParser can screw soundgen data if present and TESCS dialog export/import can have problems with line breaks though, so verify results as needed.