Difference between revisions of "Operator Element"

466 bytes added ,  13:10, 21 December 2023
no edit summary
imported>Low Post
(→‎Boolean Operators: Added <and>, <or>, <not>.)
Tag: Manual revert
 
(4 intermediate revisions by 3 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>       
   <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>   
   <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.  The Copy operator, however, can still be used with strings.
'''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> &lt;!-- Set the new x position to be 50 pixels --&gt;
   <x> &lt;!-- Set the x position to be 50 pixels --&gt;
       <Copy> 50 </Copy>
       <Copy> 50 </Copy>
   </x>
   </x>
   <y> &lt;!-- Set the new y position to match y position of "otherimage" --&gt;
   <y> &lt;!-- Set the y position to match y position of "someimage" --&gt;
       <Copy src="otherimage" trait="y" />
       <Copy src="someimage" trait="y" />
   </y>
   </y>
  </image>
  <string> &lt;!-- Set the text content to match the "user4" property --&gt;
There is a special mechanic built in for copying values from 'custom' property elements that have types of the form ''_CustomPropertyName_#'', where # is an integer greater than zero. In this case, it is possible to set the '[[Traits|trait]]' to just ''_CustomPropertyName_'' and the engine will ''automatically'' append the current value of the property to the end. For example:
      <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>
  <image>
     <user0> </user0> &lt;!-- set by script or end user to 1,2, or 3 --&gt;  
     <user0> </user0> &lt;!-- set by script or end user to 1,2, or 3 --&gt;  
     <_srcfile_1> MyMod\apple.dds  </_srcfile_1>
     <_srcfile_1> MyMod\apple.dds  </_srcfile_1> &lt;!-- Custom properties ... --&gt;
     <_srcfile_2> MyMod\pear.dds  </_srcfile_2>
     <_srcfile_2> MyMod\pear.dds  </_srcfile_2>
     <_srcfile_3> MyMod\banana.dds </_srcfile_3>
     <_srcfile_3> MyMod\banana.dds </_srcfile_3>
     <filename>  
     <filename>  
       <copy src="me()" trait="user0" /> &lt;!-- current value set to user selection --&gt;  
       <copy src="me()" trait="user0" /> &lt;!-- current value set to the integer in "user0" --&gt;  
       <copy src="me()" trait="_srcfile_"/> &lt;!-- which then determines which file --&gt;  
       <copy src="me()" trait="_srcfile_"/> &lt;!-- which determines which custom property --&gt;  
     </filename>                            &lt;!-- path is actually copied --&gt;  
     </filename>                            &lt;!-- the filename is actually copied from --&gt;  
  </image>
  </image>
As implied by the example above, the Copy operator is the only operator that will work with string values, both as literals and copied from other string-type properties.


== Algebraic Operators ==
== Algebraic Operators ==
Line 89: Line 97:


== Comparative Operators ==
== Comparative Operators ==
*'''Min''' - The current value greater than the value of <min>, it is set to that value.
*'''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''' - If current value is less than the value of <max>, it is set to that value.
*'''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]]
Anonymous user