In some responses to people, I've mentioned polling, a method used in scripting that can cause damaging leftover scripts in saves if not done right. They've asked me what it means, so I figured I would create an article about what it is, and why it's damaging. So here it is.
The Problem
So let me explain polling. Polling is essentially a method used in scripting that constantly checks if a condition is true, often using RegisterforUpdate, though Whiles are also an issue depending on what you're doing. Here's an example:
Weather Property CoolWeather Auto
Event OnInit()
RegisterForUpdate(1.0)
EndEvent
Event OnUpdate()
If GetCurrentWeather() == CoolWeather
UnregisterforUpdate()
;do some cool stuff
EndIf
EndEvent
Now RegisterForUpdate is the main contributor to situations like these. It essentially sends the event OnUpdate every set amount of time (declared in the parentheses), and it can only be stopped by calling UnregisterForUpdate. There are several problems with the above approach. The first one you can probably already imagine. If the game has to check every second if the weather is CoolWeather, that could be a problem - for this script, which doesn't do much, the load wouldn't be awful, but if you had 20 functions in that script... well, you can imagine. This is hard on the game, and can cause script lag if used often with large blocks of code. Secondly, because it's using RegisterForUpdate and not RegisterForSingleUpdate, if you uninstall the mod with the above script, it will keep trying to RegisterForUpdate, even though the script is gone - because an instance of the script is still in your game. Unless, of course, the If statement evaluated to true at some point. This leaves residual scripts in your save, which can cause instability and crashes.
Some Solutions
Using RegisterForSingleUpdate, and then RegisterForSingleUpdate again in the event OnUpdate is certainly safer, so if you have to create a constant check then you should use that. Since it only registers for it once each time, if you uninstall the mod and script, the script will try one more time, and then stop. Also, wherever possible, try to avoid intervals for updates that are extremely short, and/or doing a lot OnUpdate with a short interval. My mod Simple Taxes uses RegisterForSingleUpdateGameTimes, with the lowest interval being an in-game day. That's alright. The game can cope with that. An added benefit with RegisterForSingleUpdates is that you can change the interval every OnUpdate, like I did in this tutorial.
Something else you can do is use a magic effect, and have conditions on the spell the magic effect is attached to. This checks for the condition every second, but in a far, far less taxing way then via script. IF you can use this method, and it's an alternative to a lot of polling, often, I recommend using the MGEF method.
Something else you can do is use a magic effect, and have conditions on the spell the magic effect is attached to. This checks for the condition every second, but in a far, far less taxing way then via script. IF you can use this method, and it's an alternative to a lot of polling, often, I recommend using the MGEF method.