Arithmetic Expressions Within Tag Expressions

From HLKitWiki
Jump to: navigation, search

Context: HL KitBasic Concepts and Terminology … Tags and Tag Expressions 

Overview

There will be times when you will need more than just a simple total of objects that match a set of criteria. For example, what if you need to calculate the combined total between two different groups of objects? Or the ratio between two groups of objects? In these situations, you will need to utilize an arithmetic expression to perform the calculation desired.

Usage and Syntax

Arithmetic expressions utilize the same basic syntax you learned back in elementary school. Expressions are formed out of numeric values that are combined using the standard arithmetic operators: '+', '–', '*', and '/'. An additional operator, %, can also be used that yields the modulus (i.e. remainder) after division (e.g. "5 % 3" would yield "2"). Arithmetic expressions can utilize parentheses to dictate how evaluation should be performed, with standard rules for arithmetic being used when no parentheses are specified (i.e. multiplication and division take precedence over addition and subtraction).

The numeric values within an arithmetic expression must be either a literal value of some sort (e.g. "3") or a standard tag term suitable for the context that yields a value. For example, within the context of a rule, tag terms can use the syntax "val:component.spell?". This same term could be used freely within an arithmetic expression that is utilized within a rule.

The following is an example tag expression that incorporates an arithmetic expression within it. In this example, the tag "color.red" must be defined, the tag "move.fast" must be defined, and the combined values of the "attack.?" and "defense.?" tags must be no more than 5.

color.red & (val:attack.? + val:defense.? <= 5) & move.fast

Important Considerations

Be sure to keep the following issues in mind when dealing with arithmetic expressions.

  • Arithmetic expressions may contain any number of terms within them. However, a maximum of 20 special terms may be utilized within a single arithmetic expression. A special term is any non-literal value (e.g. "val:attack.?"). This probably seems like an absurdly high number for any typical use for a role-playing game, but the limit needs to be specified for completeness. If you define an arithmetic expression that contains more than 20 special terms, the expression will fail to compile and be reported as containing a syntax error.