Mod:Creation Kit/Safely increment variable from multiple scripts

=The Problem=

Say the player needs to kill X of some creature. One common way to do this is put an OnDeath script on all the creatures, increment a quest variable, then do something when the count gets to the right number.

This can cause problems because it isn’t thread safe – meaning if two enemies die at exactly the same moment, one may end up bashing the other, preventing the player from getting credit for one of the kills.

=The Solution=

Instead of incrementing the variable from the other scripts, it's better to use a function on the quest script (where applicable) which increments the variable and does whatever it needs to when the count gets to the right number. This is thread-safe (because it is a function call). So, for example, instead of doing this:

I changed it to this on the actor script:

And then put this on MS06Script: