Operator Element
Overview
Operator Elements are a subgroup of the elements in the Oblivion XML schema, always found as children of Property Elements. They are used to create mathematical formulas, which the game engine evaluates in real time to get the property value.
There is pretty much an Operator Element for every basic mathematical operator - at least every operator that takes two operands. The first operand is always the current value of the property (i.e. whatever the value was the previous frame). If the operator contains a literal number or string, that is used as the second operand. For example:
<image> <x> <!-- Move image 1 pixel to the right every frame --> <add> 1 </add> <!-- (Add 1 to current x position) --> </x> </image>
However, Operators can instead refer to other properties for the value of their second operand, or even properties of other Object elements. For example:
<image name="example_image> <y> 5 </y> <!-- Move image 5 pixels to the right every frame --> <x> <!--Add the value of the y coordinate (5) to the current x position --> <add src="example_image" trait="y"/> </x> </image>
Here src and trait are XML traits indicating the Object & Property, respectively, to get the value from. Don't be confused: The XML trait called trait here actually refers to a Property Element, not another XML trait. It seems Bethesda used the word differently than the XML community at large.
A property element may contain more than one Operator, evaluating them in order:
<image> <x> <!-- New X = (X + 10) * 2 --> <add> 10 </add> <mult> 2 </mult> </x> </image>
Operator Elements may contain other operator elements as children to make more complicated formulas:
<image> <x> <!-- New X = X + (10 / 3) --> <add> <copy> 10 </copy> <div> 3 </div> </add> </x> </image>
Note that numerical operators (which is most of them) aren't intended for use with string-type properties. If a numerical operator is used in a string-type property or specifies a string as its second operand the result seems to be undefined. However, the Copy operator can be used with strings, as described below.
Described below are some of the more common Operator elements.
Copy Operator
The only unary (single-operand) operator. The <copy> operator replaces the current property value with its contents:
<image> <x> <!-- Set the new x position to be 50 pixels --> <Copy> 50 </Copy> </x> </image>
Algebraic Operators
- Add - Addition
- Sub - Subtraction
- Mult/Mul - Multiplication (different elements, but both perform exactly the same function)
- Div - Floating point division
- Mod - Modulus (the remainder of the current value / contents of <mod>)
Boolean Operators
With these operators the numerical value of 'true' is encoded as the XML entity "&true;", or the literal number 2. The standard numerical value of 'false' is "&false;", or 1, but any number other than 2 will be considered false.
- Onlyif - The new property value is the current property value if the contents of <onlyif> evaluate to &true;, and zero if the contents evaluate to &false;.
- Onlyifnot - Similar to <onlyif>, but with the opposite pairing.
- Lt - The new property value is &true; if the current value is less than the contents of <lt>, and &false; otherwise.
- Gt - Similar to <lt>, but the current value must be greater than the contents of <gt>.
- Eq - The new property value is &true; if the current value is equal to the contents of <eq>, and &false; otherwise.
- Neq - Similar to <eq>, but the current value must be unequal to the contents of <neq>.
Comparative Operators
- Min - The new value is current value or the contents of <min>, whichever is greater.
- Max - The new value is the current value or the contents of <max>, whichever is less.