Expression Syntax
Expressions are evaluated at runtime using the monster’s stats. The parser supports numbers, dice notation, ability modifiers, operators, and functions.
Basic Elements
Section titled “Basic Elements”Numbers
Section titled “Numbers”542-3Dice Notation
Section titled “Dice Notation”2d6 # Roll 2 six-sided dice4d8 # Roll 4 eight-sided dice1d20 # Roll 1 twenty-sided die10d10 # Roll 10 ten-sided diceAbility Score Modifiers
Section titled “Ability Score Modifiers”Use lowercase ability abbreviations to reference modifiers:
| Token | Ability |
|---|---|
str | Strength |
dex | Dexterity |
con | Constitution |
int | Intelligence |
wis | Wisdom |
cha | Charisma |
Special Variables
Section titled “Special Variables”| Token | Description |
|---|---|
prof | Proficiency bonus (derived from CR) |
level | Creature level (typically 0 for monsters) |
Operators
Section titled “Operators”| Operator | Description |
|---|---|
+ | Addition |
- | Subtraction |
* | Multiplication |
/ | Division |
Operator Precedence
Section titled “Operator Precedence”Standard math precedence applies:
- Parentheses
() - Multiplication and Division
*,/ - Addition and Subtraction
+,-
Functions
Section titled “Functions”max(a, b)
Section titled “max(a, b)”Returns the larger of two values:
max(str, dex) # Higher of STR or DEX modmax(10, 8 + prof) # At least 10min(a, b)
Section titled “min(a, b)”Returns the smaller of two values:
min(str, 5) # Cap at +5min(dex + prof, 10) # Maximum of 10Grouping
Section titled “Grouping”Use parentheses to control evaluation order:
(str + prof) # Evaluate together(2 + 3) * 2 # Evaluates to 10str + (prof * 2) # Double proficiency added to STRExpression Output
Section titled “Expression Output”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