Skip to content

Expression Syntax

Expressions are evaluated at runtime using the monster’s stats. The parser supports numbers, dice notation, ability modifiers, operators, and functions.

5
42
-3
2d6 # Roll 2 six-sided dice
4d8 # Roll 4 eight-sided dice
1d20 # Roll 1 twenty-sided die
10d10 # Roll 10 ten-sided dice

Use lowercase ability abbreviations to reference modifiers:

TokenAbility
strStrength
dexDexterity
conConstitution
intIntelligence
wisWisdom
chaCharisma
TokenDescription
profProficiency bonus (derived from CR)
levelCreature level (typically 0 for monsters)
OperatorDescription
+Addition
-Subtraction
*Multiplication
/Division

Standard math precedence applies:

  1. Parentheses ()
  2. Multiplication and Division *, /
  3. Addition and Subtraction +, -

Returns the larger of two values:

max(str, dex) # Higher of STR or DEX mod
max(10, 8 + prof) # At least 10

Returns the smaller of two values:

min(str, 5) # Cap at +5
min(dex + prof, 10) # Maximum of 10

Use parentheses to control evaluation order:

(str + prof) # Evaluate together
(2 + 3) * 2 # Evaluates to 10
str + (prof * 2) # Double proficiency added to STR

When an expression is parsed, it produces a result object containing:

{
dice: { d6: { numberOfDice: 2, die: 'd6' } }, // Dice components
avgResult: 7, // Average expected result
expressionValue: 3, // Non-dice component
expression: "2d6 + str" // Original expression
}

This allows the system to:

  • Display the average value
  • Roll the dice when needed
  • Show the original expression