Mathematical and Comparison Expressions
Beyond simple dice rolls, you can perform standard mathematical calculations and comparisons. These operations work on the numeric results of any preceding part of the formula, whether that's a constant number, the total from a dice roll, the outcome of a function, or even a referenced value.
Mathematical Operators
Standard operators are available:
`+` Addition
`-` Subtraction or unary negation when used as a prefix (e.g. `-(2d6)` or `-d8`).
`*` Multiplication
`/` Division
`**` Exponentiation
`%` Modulo (remainder)
Comparison Operators
You can compare numeric results using:
`>` Greater than
`<` Less than
`>=` Greater than or equal to
`<=` Less than or equal to
`=` Equal to
Comparison operations evaluate to `1` if the condition is true, and `0` if it is false.
Order of Operations and Grouping
Standard mathematical order of operations (PEMDAS/BODMAS) applies. You can use parentheses `()` to explicitly group parts of your formula and control the calculation order, just like in regular math.
Combining Expressions
The real power comes from combining these operations with different elements:
Constants: `5 * 3` (Result: `15`)
Dice Results: `2d6 + 5`
Example: Roll `[3, 4]` -> `7 + 5 = 12`Combined Dice/Expressions: `(1d10 + 1d8) * 2`
Example: Roll `1d10=[7]`, `1d8=[5]` -> `(7 + 5) * 2 = 12 * 2 = 24`Function Results: `floor(1d10 / 2) >= 3`
Example: Roll `1d10=[9]` -> `floor(9 / 2) = floor(4.5) = 4`. `4 >= 3` is true, Result: `1`Referenced Values: `@{attack_bonus} + d20 > 15`
Example: If `@{attack_bonus}` evaluates to `5`, Roll `d20=[12]` -> `5 + 12 = 17`. `17 > 15` is true, Result: `1`
This flexibility allows you to build complex formulas that evaluate down to a single final number or a 1/0 comparison result, enabling intricate game mechanics and reusable formula components (via references `@{id}`).
Important Syntax Note
Remember that these mathematical and comparison operators typically require spaces around them (e.g., `2d6 + 5`, `d20 > 10`) or parentheses around the dice part (e.g., `(2d6)+5`, `(d20)>10`) to distinguish them from dice modifiers (like `4d6k3`, `5d10>7`), which use similar symbols but operate very differently on the individual dice before summing. See the next section for crucial details on this distinction.