Difference between revisions of "Operator Element"

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search
imported>JRoush
m
Tag: Manual revert
 
(12 intermediate revisions by 4 users not shown)
Line 2: Line 2:
Operator Elements are a subgroup of the elements in the [[:Category: Oblivion XML|Oblivion XML]] schema, always found as children of [[Property Element]]s.  They are used to create mathematical formulas, which the game engine evaluates in real time to get the property value.
Operator Elements are a subgroup of the elements in the [[:Category: Oblivion XML|Oblivion XML]] schema, always found as children of [[Property Element]]s.  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).
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. the value after evaluation of the previous operator, or the value from the previous update for the first operator). If the operator contains a literal number or string, that is used as the second operand.  For example:
If the operator contains a literal number or string, that is used as the second operand.  For example:
  <image>
  <image>
   <x>               &lt;!-- Move image 1 pixel to the right every frame --&gt;
   <x>      
     <add> 1 </add>  &lt;!-- (Add 1 to current x position) --&gt;
    <copy> 1 </copy>  &lt;!-- Set the current x position to 1 --&gt;
     <add> 5 </add>  &lt;!-- Add 5 to current x position --&gt;
   </x>
   </x>
  </image>
  </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:
 
However, Operators can instead refer to ''properties'' for the value of their second operand, using the [[XML Attribute|src]] and [[XML Attribute|trait]] XML attributes.  This include properties of other object elements.  See the attributes page for details on this syntax.  An example:
  <image name="example_image>
  <image name="example_image>
   <y> 5 </y>       &lt;!-- Move image 5 pixels to the right every frame --&gt;
   <y> 5 </y>
   <x>  &lt;!--Add the value of the y coordinate (5) to the current x position --&gt;
   <x>  &lt;!-- Set the current x position to the value of the y coordinate (5) --&gt;
     <add src="example_image" trait="y"/>  
     <copy src="example_image" trait="y"/>  
   </x>
   </x>
  </image>
  </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:
A property element may contain more than one Operator, evaluating them in order:
  <image>
  <image>
   <x>
   <x>
     &lt;!-- New X = (X + 10) * 2 --&gt;
     &lt;!-- New X = (5 + 10) * 2 --&gt;
    <copy> 5 </copy>
     <add> 10 </add>
     <add> 10 </add>
     <mult> 2 </mult>  
     <mul> 2 </mul>  
   </x>
   </x>
  </image>
  </image>


Operator Elements may contain other operator elements as children to make more complicated formulas:
Operator Elements may contain other operator elements as children to make more complicated formulas or for when operator precedence is needed:
  <image>
  <image>
   <x>
   <x>
     &lt;!-- New X = X + (10 / 3) --&gt;
     &lt;!-- New X = 5 + (10 / 3) --&gt;
    <copy> 5 </copy>
     <add>  
     <add>  
       <copy> 10 </copy>
       <copy> 10 </copy>
Line 38: Line 40:
  </image>
  </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.
'''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 has a string as its second operand the result seems to be undefined.  The Copy operator is a notable exception (see below).


Described below are some of the more common Operator elements.
Described below are some of the more common Operator elements.


== Copy Operator ==
== Copy Operator ==
The only unary (single-operand) operator.  The <copy> operator ''replaces'' the current property value with its contents:
The only unary (single-operand) operator, and the only operator that will work with string values.  The <copy> operator ''replaces'' the current property value:
  <image>
  <text>
   <x>
   <x> &lt;!-- Set the x position to be 50 pixels --&gt;
      &lt;!-- Set the new x position to be 50 pixels --&gt;
       <Copy> 50 </Copy>
       <Copy> 50 </Copy>
   </x>
   </x>
  <y> &lt;!-- Set the y position to match y position of "someimage" --&gt;
      <Copy src="someimage" trait="y" />
  </y>
  <string> &lt;!-- Set the text content to match the "user4" property --&gt;
      <Copy src="Me()" trait="user4" />
  </string>
</text>
Copy has a special mechanic built in for "choosing" one of several source properties:
# Define a "custom" property for each choice with names of the form ''_SomeName_#'', where # is an integer greater than zero.
# Set the value of the destination property to the integer corresponding to the desired choice.
# Use <Copy> with [[XML Attribute|trait]]="_CustomPropertyName_"
The engine will ''automatically'' append the current integer value to the end of the requested trait name, and copy the value of the resulting property.  This is extremely useful for conditional formulas, as an alternative to loads of nested Onlyif blocks.
For example:
<image>
    <user0> </user0> &lt;!-- set by script or end user to 1,2, or 3 --&gt;
    <_srcfile_1> MyMod\apple.dds  </_srcfile_1> &lt;!-- Custom properties ... --&gt;
    <_srcfile_2> MyMod\pear.dds  </_srcfile_2>
    <_srcfile_3> MyMod\banana.dds </_srcfile_3>
    <filename>
      <copy src="me()" trait="user0" /> &lt;!-- current value set to the integer in "user0" --&gt;
      <copy src="me()" trait="_srcfile_"/> &lt;!-- which determines which custom property --&gt;
    </filename>                            &lt;!-- the filename is actually copied from --&gt;
  </image>
  </image>


Line 57: Line 80:
*'''Div''' - Floating point division
*'''Div''' - Floating point division
*'''Mod''' - Modulus (the remainder of the current value / contents of <mod>)
*'''Mod''' - Modulus (the remainder of the current value / contents of <mod>)
*'''Rand''' - Random number (between 0 and the contents of <rand>).


== Boolean Operators ==
== Boolean Operators ==
Line 62: Line 86:
*'''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;.
*'''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.
*'''Onlyifnot''' - Similar to <onlyif>, but with the opposite pairing.
*'''And''' - The new property value is &true; if the contents of <and> ''and'' the current property value both evaluate to &true;, and &false; if at least one of them evaluates to &false;.
*'''Or''' - The new property value is &true; if the contens of <or> ''or'' the current property value (or both) evaluates to &true;, and &false; if both of them evaluate to &false;.
*'''Not''' - The new property value is &true; if the contents of <not> evaluate to &false;, and &false; if the contents evaluate to &true;.
*'''Lt''' - The new property value is &true; if the current value is less than the contents of <lt>, and &false; otherwise.
*'''Lt''' - The new property value is &true; if the current value is less than the contents of <lt>, and &false; otherwise.
*'''Lte''' - Similar to <lt>, but the current value can be lesser than or equal to the contents of <lte>.
*'''Gt''' - Similar to <lt>, but the current value must be ''greater than'' the contents of <gt>.
*'''Gt''' - Similar to <lt>, but the current value must be ''greater than'' the contents of <gt>.
*'''Gte''' - Similar to <gt>, but the current value can be greater than or equal to the contents of <gte>.
*'''Eq''' - The new property value is &true; if the current value is equal to the contents of <eq>, and &false; otherwise.
*'''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>.
*'''Neq''' - Similar to <eq>, but the current value must be ''unequal'' to the contents of <neq>.


== Comparative Operators ==
== Comparative Operators ==
*'''Min''' - The new value is current value or the contents of <min>, whichever is ''greater''.
*'''Min''' - The new property value is the lesser of the current value and the contents of <min>, i.e. the minimum of the two values.  Used to put an ''upper'' limit on the value of the property.
*'''Max''' - The new value is the current value or the contents of <max>, whichever is ''less''.
*'''Max''' - Similar to Min.  The new property value is the greater of the current value and the contents of <max>.


[[Category:Oblivion XML]]
[[Category:Oblivion XML]]

Latest revision as of 12:10, 21 December 2023

Overview[edit | edit source]

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. the value after evaluation of the previous operator, or the value from the previous update for the first operator). If the operator contains a literal number or string, that is used as the second operand. For example:

<image>
  <x>       
    <copy> 1 </copy>  <!-- Set the current x position to 1 -->
    <add> 5 </add>  <!-- Add 5 to current x position -->
  </x>
</image>

However, Operators can instead refer to properties for the value of their second operand, using the src and trait XML attributes. This include properties of other object elements. See the attributes page for details on this syntax. An example:

<image name="example_image>
  <y> 5 </y>  
  <x>  <!-- Set the current x position to the value of the y coordinate (5) -->
    <copy src="example_image" trait="y"/> 
  </x>
</image> 

A property element may contain more than one Operator, evaluating them in order:

<image>
  <x>
    <!-- New X = (5 + 10) * 2 -->
    <copy> 5 </copy>
    <add> 10 </add>
    <mul> 2 </mul> 
  </x>
</image>

Operator Elements may contain other operator elements as children to make more complicated formulas or for when operator precedence is needed:

<image>
  <x>
    <!-- New X = 5 + (10 / 3) -->
    <copy> 5 </copy>
    <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 has a string as its second operand the result seems to be undefined. The Copy operator is a notable exception (see below).

Described below are some of the more common Operator elements.

Copy Operator[edit | edit source]

The only unary (single-operand) operator, and the only operator that will work with string values. The <copy> operator replaces the current property value:

<text>
  <x> <!-- Set the x position to be 50 pixels -->
     <Copy> 50 </Copy>
  </x>
  <y> <!-- Set the y position to match y position of "someimage" -->
     <Copy src="someimage" trait="y" />
  </y>
  <string> <!-- Set the text content to match the "user4" property -->
     <Copy src="Me()" trait="user4" />
  </string>
</text>

Copy has a special mechanic built in for "choosing" one of several source properties:

  1. Define a "custom" property for each choice with names of the form _SomeName_#, where # is an integer greater than zero.
  2. Set the value of the destination property to the integer corresponding to the desired choice.
  3. Use <Copy> with trait="_CustomPropertyName_"

The engine will automatically append the current integer value to the end of the requested trait name, and copy the value of the resulting property. This is extremely useful for conditional formulas, as an alternative to loads of nested Onlyif blocks. For example:

<image>
   <user0> </user0> <!-- set by script or end user to 1,2, or 3 --> 
   <_srcfile_1> MyMod\apple.dds  </_srcfile_1> <!-- Custom properties ... -->
   <_srcfile_2> MyMod\pear.dds   </_srcfile_2>
   <_srcfile_3> MyMod\banana.dds </_srcfile_3>
   <filename> 
      <copy src="me()" trait="user0" /> <!-- current value set to the integer in "user0" --> 
      <copy src="me()" trait="_srcfile_"/> <!-- which determines which custom property --> 
   </filename>                             <!-- the filename is actually copied from --> 
</image>

Algebraic Operators[edit | edit source]

  • 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>)
  • Rand - Random number (between 0 and the contents of <rand>).

Boolean Operators[edit | edit source]

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.
  • And - The new property value is &true; if the contents of <and> and the current property value both evaluate to &true;, and &false; if at least one of them evaluates to &false;.
  • Or - The new property value is &true; if the contens of <or> or the current property value (or both) evaluates to &true;, and &false; if both of them evaluate to &false;.
  • Not - The new property value is &true; if the contents of <not> evaluate to &false;, and &false; if the contents evaluate to &true;.
  • Lt - The new property value is &true; if the current value is less than the contents of <lt>, and &false; otherwise.
  • Lte - Similar to <lt>, but the current value can be lesser than or equal to the contents of <lte>.
  • Gt - Similar to <lt>, but the current value must be greater than the contents of <gt>.
  • Gte - Similar to <gt>, but the current value can be greater than or equal to the contents of <gte>.
  • 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[edit | edit source]

  • Min - The new property value is the lesser of the current value and the contents of <min>, i.e. the minimum of the two values. Used to put an upper limit on the value of the property.
  • Max - Similar to Min. The new property value is the greater of the current value and the contents of <max>.