Difference between revisions of "Operator Element"
Jump to navigation
Jump to search
Rebranding XML "traits" as "attributes"; reworded the description of Min/Max for clarity
imported>Low Post (→Boolean Operators: Added <and>, <or>, <not>.) |
imported>JRoush (Rebranding XML "traits" as "attributes"; reworded the description of Min/Max for clarity) |
||
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. | 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 frame 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> | ||
Line 9: | Line 8: | ||
</x> | </x> | ||
</image> | </image> | ||
However, Operators can instead refer to '' | 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> | ||
Line 15: | Line 14: | ||
<add src="example_image" trait="y"/> | <add src="example_image" trait="y"/> | ||
</x> | </x> | ||
</image> | </image> | ||
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: | ||
Line 38: | Line 36: | ||
</image> | </image> | ||
Note that numerical operators (which is most of them) aren't intended for use with string-type properties. If a numerical operator | '''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 with its contents: | ||
< | <text> | ||
<x> <!-- Set the | <x> <!-- Set the x position to be 50 pixels --> | ||
<Copy> 50 </Copy> | <Copy> 50 </Copy> | ||
</x> | </x> | ||
<y> <!-- Set the | <y> <!-- Set the y position to match y position of "someimage" --> | ||
<Copy src=" | <Copy src="someimage" trait="y" /> | ||
</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: | |||
# 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> <!-- set by script or end user to 1,2, or 3 --> | <user0> </user0> <!-- set by script or end user to 1,2, or 3 --> | ||
<_srcfile_1> MyMod\apple.dds </_srcfile_1> | <_srcfile_1> MyMod\apple.dds </_srcfile_1> <!-- Custom properties ... --> | ||
<_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" /> <!-- current value set to | <copy src="me()" trait="user0" /> <!-- current value set to the integer in "user0" --> | ||
<copy src="me()" trait="_srcfile_"/> <!-- which | <copy src="me()" trait="_srcfile_"/> <!-- which determines which custom property --> | ||
</filename> <!-- | </filename> <!-- the filename is actually copied from --> | ||
</image> | </image> | ||
== Algebraic Operators == | == Algebraic Operators == | ||
Line 89: | Line 93: | ||
== Comparative Operators == | == Comparative Operators == | ||
*'''Min''' - The current 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''' - | *'''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]] |