Skip to content

FormulaEngine Concepts Formulas

Mike Lewis edited this page Feb 28, 2016 · 1 revision

FormulaEngine Concepts - Formulas

Perhaps the single most foundational notion in FormulaEngine is that of the formula. A formula is simply a mathematical expression which evaluates to a value. It can be a simple literal number, such as 3.14159, or it can be a more complex combination of properties, functions, and literals - such as PI * Square(Radius).

In general, formulas are the mechanism for expressing relationships between numbers in FormulaEngine. The amount of damage done by a weapon, for instance, might be computed using a formula. That formula might draw upon properties of not just the weapon but also the wielder. A formula can combine numbers using any basic arithmetic operation (+ - * /) as well as precedence control (parentheses). Further, formulas can use functions to do more complex computations that are not easily expressed using arithmetic.

Further, formulas can access lists using various functions. This allows lists to store arbitrary amounts of data which is then "rolled up" or aggregated by a formula.

Types

Formulas are not limited to just single scalar numbers. The FormulaEngine implementation currently supports 2D vectors as well as tokens, which are basically integer ID numbers that map to predefined text strings. Mixing types is often an error that will cause failures in the engine, so be sure your formula makes sense from a type perspective if something is going wrong.