On script variables persistence

Posted on TESforums 31 July 2009 - 08:44 PM

For anybody interested, I've found in my archives an interesting post by CDCooley explaining variables persistance much better than myself :)

cdcooley @ Aug 13 2005, on 06:36 PM, said:

Variables in local scripts (attached to items from the CS) keep their values forever.

The true global variables keep their state forever.

Variables in global scripts (the ones that are listed if you use SV in the console with no objects selected) can forget their values under one very specific case.

If the script isn't used between the time the game is loaded and then saved again, any old values from the previous save game file will be lost since the game assumes that if you didn't run it this time, it must not be important.

So if you want a global script to remember it's values you have to make sure it gets run at least once every time a game is loaded.

The "72 hour bug" affects NPC stats and other values you might change from within scripts, but the scripts themselves aren't affected.

Companion mods actually use the variables in a script to keep track of the companion's stats and skills since any changes to the NPC itself can disappear if you leave it alone too long.