Having a look at this right now and to the best of my understanding it's as good as it can be,
Vanilla:
Short RespawnHorse
Short TellPC
Short Mounted
DLC:
Short RespawnHorse
short FakeDeath
UOMP:
Short RespawnHorse
Short TellPC
Short Mounted
short FakeDeath
Long ItemsStolen
Long BountyGold
...
Agreed! Inserting a variable at the top instead of adding one at the bottom, or changing the variable type of an existing one to one of a different size in bytes would definitely be a bad idea.
The order of the variable declarations in the
script source is totally irrelevant.
The system works like this:
The SCPT record (and other places where scripts occur, like quest scripts) contains an array of SLSD/SCVR sub record pairs.
The SLSD subrecord contains an index number, the SCVR the variable name.
These subrecords define a mapping between variable names and index numbers.
When you compile a script, the first thing that happens is that this mapping as it already existed (from previous compilations of the script) is being loaded in. All variables for which a mapping already existed will keep their index number, no matter in what order they occur in the source. All mappings for variables which are not longer in the source are deleted. And all variables still left will get new indexes assigned starting after the highest index that ever was assigned to any variable for this script before.
If you have a script with a variable, compile it, remove that variable, compile it again, add a variable with the same name, compile again then this variable will now have a different index number then it had before.
Now suppose you got a script from oblivion.esm, and you got 2 different esp's which override that script.
Suppose you start editing the first of the 2 plugins, adding a variable:
Short B
compile (the variable with the name B now gets it's index assigned), play around with the script, try different things... then you need another variable, so you add:
Short A
in front of Short B, compile (the variable with the name A now gets it's index assigned, which is higher then the index for variable B even tho variable B is declared further down in the script source).
After some further editing you are done with the script. Great. You copy the whole script text, close this esp, open the other esp, past in the complete script and compile.
But now on this compile there is no index assignment yet for both variable A and variable B. And because variable A came first in the source it got it's index assigned first.
You now got 2 esp's containing 2 times the exactly same script text. But the variables A and B now got different indexes assigned in these 2 plugins!
Variable names have no meaning except during the compilation of the script. All the compiled script data only ever refers to variable indexes. And the save game only contains the information variable x contains value y.
So if you now start the game with the first of the 2 plugins loaded, the script runs, writes values into the 2 variables, you save the game, exit oblivion, add the 2nd plugin to the load order after the first (or replace the first with the 2nd), start again, load the savegame. When the script runs it will find whatever value was written into variable A is now in variable B and whatever value was in B is now in A. Because the save game only had values stored for index 5 and 6 and with one script 5 and 6 are B and A, and with the other they are A and B.
Obviously this is especially bad if one of the 2 variables was a ref and the other some numerical value. But even if it's just 2 variables with numbers that get mixed up it can cause real problems.
You can fix such problems with TES4Edit by opening the SCPT record and changing the index values so that the same variable name has the same index in all involved files (keeping in mind whatever effect changing indexes will have on already existing save games..). There is no problem with having holes in the sequence, so a script can have a variables 1, 2, 6, 9 defined.
Also, in the SCHR subrecord you'll find a VariableCount value. That name is actually not quite right. It's not the number of variables in the script, it's the number that will be used as the next variable index if a compile finds a variable name for which no index is yet assigned. So that value should be larger then the highest variable index currently defined.
Hope this clears up any confusion...