Talk:GetModIndex

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search

Munch Universe, based on advice from Kyoma, May 25, 2013: The output of this function is the sought-for mods position in the load order, expressed in decimal numbers (base 10: 0-9). The game engine, however, uses the position in the load order expressed in a two digit string corresponding to hexadecimal numbers (base 16: 0-F). The statement that the output corresponds to the first two digits of a reference's FormID is only true up to position 09 in your load order, thereafter the two will diverge.

This creates a problem if you try to use the decimal output to create the correct formID for an object from a foreign mod. Here is an example:

If used in a statement like the following, you must use %x to convert the decimal number into a hexadecimal for the formID:

   runScriptLine "set rNewItem to placeAtMe %x200237A" FFRTIndex 1

Alternately the same problem can be solved this way:

   ref rWaterSkin
   ....
   if GetModLoaded == 1
       set rWaterSkin to (getFormFromMod "FF_Real_Thirst.esp" "000515AE")
                ; the first two digits are ignored and can be omitted
   endif
   ....
   set rNewItem to placeAtMe rWaterskin 1
 

This version has the advantage that the foreign object is assigned to a reference variable once and thereafter can be used as if native.

The load order shown by Wrye Bash is expressed in hexadecimal, so do not be surprised if the output of the function gives you a different value than Bash, provided the mod is after position 09 in your load order.


No and yes, actually.
Numbers are concepts that, usually, must be represented somehow in order to be used.
We, humans, represent it on a decimal notation, so the number eleven is represented as ‘11’
Computers use a binary system, so eleven is represented as ‘1011’ (which, itself, is a representation of the internal, electronic on-off states). Since the binary notation is not easy to follow, for convenience, we group 4 binary digits in an hexadecimal notation. So, in hex, eleven is represented as ‘0B’.
This function returns a ‘short’, which, as all other numeric variables (int, long, float), is an hex representation of the intended number.
The point is how you want to ‘see’ it: if you want to see it as hex, you use the %x format specifier, if you want to see it as decimal, you use the %f or %g specifier.
In your case, as you already mentioned, in order to ‘construct’ a FormID, you need it as an hex, so you must use the %x2 specifier.
QQuix (talk) 10:03, 26 May 2013 (EDT)