Home > Tutorials > Beware the Dangers of module_core

Beware the Dangers of module_core

I had originally sat down tonight to continue on with part 2 of our custom merchant tutorial, but then I found some interesting information spreading its way around the DAMods forum.

Many people have been experiencing some odd issues caused either by mods they installed, or by mods they had made.  Some of these issues included really bad performance in cutscenes and conversations, slow overall performance, and issues with leveling up such as attribute point spending being incorrect.  Recently it appears that the cause of these problems has been discovered, and I thought this important enough to break from my normal plans and bring you a short article about the subject.

The root of the problem, it appears, is the “module_core” script. DAScripts are mostly event driven.  When the engine encounters an event, it then sends that off to whatever object is the target of the event.  This could be the module, an area, the player, a creature, etc.  The object then runs its “core” script, which contains all the event handling code.  For the module itself, this is the “module_core” script, which by default is set to “module_core” as seen below.

What that means is that all events for the module will be sent to the script, “module_core”.  This script already exists in the Core Game Resources, and it handles many events.  What appears to be happening though is that if you leave it at the default, then the “module_core” script actually gets called twice!  Once for your module, then again for the Single Player module.  This is what is causing all the issues.

Now I believe this will only occur if your module extends Single Player, but most do.

So how do we fix this problem?  The answer is actually quite simple.  We just want to make sure that any module we make that extends another module, has its own custom “module_core”.  Now some mods actually do this anyway because they need to trap certain events, but not all do, so let me be clear. Even if you mod does not need to process any events, you still need a custom module_core handler script to prevent this problem.

If your mod does not need to process any events, then just create a new script and make it essentially blank, like so:

void main()
{
}

Then assign this blank script to be your module’s “module_core” script.

Now if your module does need to process custom events, you would already be creating (or should be creating) your own script anyway, only one that processes the events. If this is the case there is one more very important thing to be aware of. Contrary to what the Wiki says, you should not pass events back to “module_core” using HandleEvent(), as this will cause the same sort of duplication in many cases. It shouldn’t, and it makes no sense that it does, but I have seen it first hand.

Now in truth the issue is probably a bit more complicated than this, and i’m sure we’ll narrow down things more in the days and weeks to come, but in the meantime I implore all mod authors to be aware of this issue, as it will affect a great many mods and will ultimately cause a problem for players.

New Information: Thanks to weriKK on the Bioware forums for pointing out something that I had somehow managed to miss.  There is actually no need to create an empty script like above.  Instead if you open the window to choose a script, there is a (none) option you can select.

Categories: Tutorials
  1. newyears1978
    November 16, 2009 at 9:29 pm

    Does this make anything in the Merchant tutorial part 1 invalid? Do we need to make any changes or is it safe as is?

    • John Vanderbeck
      November 16, 2009 at 10:03 pm

      Good point. I think we do have an issue there.

  2. John Vanderbeck
    November 16, 2009 at 10:22 pm

    Good call newyears1978. I’ve updated that tutorial, and i’ll mention it again in part 2 so everyone knows.

  3. newyears1978
    November 16, 2009 at 11:20 pm

    Awesome, thanks for the update…will check it out.

  4. Jean
    November 17, 2009 at 3:45 am

    Great news, I just got a complaint about my mod causing extreme slowdowns in cutscenes but I had no idea where it was coming from. With this, it’s an easy fix, thanks!

    • John Vanderbeck
      November 17, 2009 at 9:29 am

      Glad it helped!

  5. Newyears1978
    November 17, 2009 at 11:57 am

    This also solves the +2 stat bug problem..so kudos!

  6. Adaram
    November 18, 2009 at 12:30 pm

    Thanks for this and all of your other articles. You have a way of explaining things that actually makes sense, and I appreciate being able to come here and learn about these sorts of things before I set off to do some module making of my own! Great great job, John!! Keep it up.

  1. November 16, 2009 at 10:22 pm
  2. November 17, 2009 at 4:01 pm

Leave a comment