This is the template script I use whenever I start building a new management script to handle various things.
It sets itself up to run startup code every time the player loads their game, and if you update the version number variable, it will run any code you place in the InstallModChanges function if it's detected that the player was using a previous version of your mod.
This ensures you can make changes to existing saves safely, so your players don't have to do clean installs each time they update your mod if you made a major adjustment.
The EditLock is something you can use to prevent race conditions. Running it at the start of a function will loop the code until the resource is free. That way you don't end up with two different calls to your quest overriding the same variables. After using EditLock, be sure to set bEditLock = false at the end of that function (or anywhere you return early).
The code will auto-clear the editlock when the player starts the game to make sure it doesn't ever get stuck permanently (which can happen if the engine fails to set the var due to a script crash or if YOU fail to set the var in your code...)
It sets itself up to run startup code every time the player loads their game, and if you update the version number variable, it will run any code you place in the InstallModChanges function if it's detected that the player was using a previous version of your mod.
This ensures you can make changes to existing saves safely, so your players don't have to do clean installs each time they update your mod if you made a major adjustment.
The EditLock is something you can use to prevent race conditions. Running it at the start of a function will loop the code until the resource is free. That way you don't end up with two different calls to your quest overriding the same variables. After using EditLock, be sure to set bEditLock = false at the end of that function (or anywhere you return early).
The code will auto-clear the editlock when the player starts the game to make sure it doesn't ever get stuck permanently (which can happen if the engine fails to set the var due to a script crash or if YOU fail to set the var in your code...)