Formula Reference
Rules systems and house rules use formulas wherever they roll dice or work out a number, for example:
- the initiative roll (
1d20 + init_bonus); - the roll each side makes when sides take turns;
- the to-hit roll (
2d6).
This page describes everything a formula can contain.
1d20 + dex_mod
floor((str - 10) / 2)
if(level >= 5, 3, 2) + 4d6kh3
Formulas are checked when you save them. If a formula has a problem, the error says what is wrong and where, for example Unexpected ")" (at 12).
Numbers and names
- Numbers: whole numbers or decimals, such as
3,0.5or.5. - Names: a name reads a value from the creature or character, such as
dex_modorinit_bonus. A name uses lower-case letters, digits and underscores, and starts with a letter or an underscore. Which names a value exists for depends on where the formula is used. A formula that reads a name with no value gives an error when it's rolled. - Spaces: spaces between parts don't matter, so
1d20+dex_modand1d20 + dex_modare the same. Keep dice together: write4d6kh3, not4d6 kh3.
Dice
| Write | Rolls |
|---|---|
1d20 or d20 | One twenty-sided die. The count defaults to 1. |
3d6 | Three six-sided dice, added up. |
d% | A percentile die, 1 to 100. Same as d100. |
4d6kh3 | Four d6, keeping the highest three. |
2d20kh1 | Two d20, keeping the higher one (advantage). |
2d20kl1 | Two d20, keeping the lower one (disadvantage). |
- Write dice in lower case:
d6, notD6. - The count must be a whole number from 1 to 100.
- A die has 2 to 1,000 sides.
khandklkeep from 1 up to all of the dice.
Arithmetic
| Operator | Meaning |
|---|---|
+ - * / | Add, subtract, multiply, divide. * and / come before + and -. |
-x | Minus, as in -dex_mod. |
( ) | Brackets, to change the order. |
- Division isn't rounded:
7 / 2is3.5. Usefloorto round down. - Dividing by zero gives an error when the formula is rolled.
Comparisons
< <= > >= == != give 1 when true and 0 when false. They're mostly used inside if, but can also be added up: (level >= 5) + 2 is 3 from level 5.
A comparison compares two things. To check a range, use if or min and max: a < b < c isn't allowed.
Functions
| Function | Gives |
|---|---|
floor(x) | x rounded down: floor(3.7) is 3, floor(-0.5) is -1. |
ceil(x) | x rounded up. |
round(x) | x rounded to the nearest whole number. Halves round up: round(2.5) is 3. |
abs(x) | x without its sign. |
min(a, b, …) | The smallest of 2 to 16 values. |
max(a, b, …) | The largest of 2 to 16 values. |
if(cond, then, else) | then when cond isn't 0, otherwise else. Only the chosen side is rolled. |
Functions always need brackets: floor(x), not floor x.
Examples
| Formula | What it does |
|---|---|
floor((str - 10) / 2) | An ability modifier from a score. |
1d20 + init_bonus | Initiative with a bonus. |
2d20kh1 + init_bonus | Initiative with advantage. |
max(1, 1d6 + str_mod) | Damage that is never below 1. |
if(level >= 11, 3, if(level >= 5, 2, 1)) | A value that goes up at levels 5 and 11. |
min(level, 10) | Level, capped at 10. |
Limits
- At most 500 characters.
- At most 200 parts (numbers, names, dice and operators).
- Brackets and functions nested at most 32 deep.