MSFD Interaction between mods
(Thanks to Emma, TheOtherFelix and Ragnar_GD for much of this information.)
Some cautions
• If you want your mod to include interaction with someone else's mod, the modder in question should be contacted first, and permissions asked.
• An update to the mod you wish to interact with may destroy compatibility if certain things are changed (another reason to ask permission first!).
• If the mod you wish to interact with is removed from the load list, this may cause problems (depending on what you want to do).
• Be very careful! Always test thoroughly to make sure you haven't broken anything.
Global variables
Global variables are not unique to a single mod: if another mod contains a variable of the same name, the last mod to load will overwrite the other, and both mods can set the global from script (Note by GBG: – one more reason why people should try to use unique names wherever possible in their mods – don't name your global "check" at least call it (your initials)_check, e.g. "YI_check" – that avoids lots of problems and compatibility issues).
This can be used to facilitate interaction between mods: by implementing a global of the same type with the same default value in your own mod, it is possible to test for the value of that global in script or dialogue without interfering with the other mod (as long as you never set the global, and make sure you give it the same default value and type, it will have no effect on the other mod). When the other mod sets the global to some value other than the default, this can be detected.
Some modders have used this simply to "declare" a mod to others, by setting a global (usually from a startscript) so that it can be detected from script or dialogue. In other cases the interaction is more complex: for example, since a global can be tested from dialogue, and dialogue resultbox scripts aren't compiled until the line is "said" in game, a global can be used as a dialogue filter for a line whose resultbox script can only be run while the second mod is loaded (e.g. starting a script or referencing an ID that doesn't exist in your mod). Another common use is in "follow globals" for companions, which may be tested in dialogue or script to detect whether an NPC from a different mod is currently in AIFollow mode.
Local variables
Emma and TheOtherFelix introduced this ingenious idea with "emmasnpcid": this local variable is declared and set to a unique value for each of Emma's companions, and can then be tested for those values in dialogue. This makes it possible to identify the companion the player is currently in dialogue with, thus opening up a great range of possibilities.
A simpler use of local variables in dialogue is to make dialogue from your mod unavailable to NPCs with that local variable, in cases where other modders might want to prevent their NPCs being affected by a particular mod.
Journal entries
It is possible to test journal entries from other mods, in much the same way as for globals. To do this, create a dummy journal topic with the same ID as the original (leave the topic blank). You can then test the journal index in your own mod. This does not interfere with the journal entries added by the original mod.