Difference between revisions of "Operator Element"

3,075 bytes added ,  13:10, 21 December 2023
no edit summary
imported>JRoush
Tag: Manual revert
 
(20 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{unfinished}}
== Overview ==
== Overview ==
Property 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 can evaluate to obtain a value for the parent property.
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, generally speaking, an Operator Element for every basic ''binary'' mathematical operator - every operator that takes exactly two operands. The first operand is always the current value of the property, and the second is the contents of the operator.  For example:
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>
  <image>
   <x>
   <x>      
     <add> 1 </add>  &lt;!-- Add one 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>
A property element may contain a series of Operators, which are evaluated in order:
 
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>
  <y> 5 </y> 
  <x>  &lt;!-- Set the current x position to the value of the y coordinate (5) --&gt;
    <copy src="example_image" trait="y"/>
  </x>
</image>
 
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:
 
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 27: Line 39:
   </x>
   </x>
  </image>
  </image>
Operator Elements may contain the value of a property for some other element somewhere in the menu:
 
<image>
'''Note''' that numerical operators (which is most of them) aren't intended for use with string-type propertiesIf 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).
  <x>
 
    &lt;!-- Place this image 10 pixels to the right of the "ExitButton" element --&gt;
Described below are some of the more common Operator elements.
    <copy src="ExitButton" trait="x"/>
    <add src="ExitButton" trait="width"/>
    <add> 10 </add>
  </x>
</image>
Here ''src'' and ''trait'' are XML [[traits]] indicating the source element and property, respectivelyDon't be confused by the use of the word 'trait' in the latter case - it's actually referring to a element (specifically a 'property' element).


== 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>


== Algebraic Operators ==
== Algebraic Operators ==
These should be self-explanatory.
*'''Add''' - Addition
*'''Add'''
*'''Sub''' - Subtraction
*'''Sub'''  
*'''Mult/Mul''' - Multiplication (different elements, but both perform exactly the same function)
*'''Mult/Mul''' - different elements, but both perform exactly the same function.
*'''Div''' - Floating point division
*'''Div''' - floating point, rather than integer, division
*'''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 58: 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]]
Anonymous user