What's new in v6? โ
Version 6 is a substantial rewrite of RPG Dice Roller. It's written in TypeScript, with a new expression-based architecture that makes it easier to build complex rolls, inspect results and customise the library to suit your application.
Many familiar dice notations still work as before, but there are breaking changes to the JavaScript API and some notation and evaluation behaviour.
Upgrading from v5?
Version 6 is not a drop-in replacement for v5. In particular, saved rolls and histories exported by v5 cannot be imported directly into v6. See Migrating from v5 to v6 for practical upgrade instructions.
Breaking changes โ
Rolling dice and working with results โ
DiceRollandDiceRollerhave been replaced byRollandRoller. The newroll()function provides a shorthand for standalone rolls.- Re-rolling with
Roll.reroll()returns a new roll rather than changing the existing result. - Roll history is now managed through
Roller.history, aRollHistoryinstance. - The old result classes have been replaced by an evaluated result tree, accessible through
roll.result. Modifier flags are semantic names rather than formatted symbols. - Calculated roll statistics (
minTotal,maxTotal,averageTotal) can now returnnullwhen unsupported. - Output formatting is handled by presenters. Use
present()instead of the oldoutputproperty.
See Rolling dice, Working with results and Roll history.
Importing and exporting โ
The import and export data structure has changed to support the expression and result trees. Version 5 exports are not directly compatible with v6. Use the data converter to migrate saved rolls and histories without rolling again.
Export formats are now specified using 'object', 'json' or 'base64', and export() returns an object by default rather than a JSON string.
Configuration and customisation โ
- The random-number implementation now uses pure-rand instead of random-js. The engine API and available built-in engines have changed. Seeded sequences are not guaranteed to match those from v5.
- Dice definitions, modifier handlers and random engines use registries. Configuration can be shared across rolls or isolated from other parts of your application, rather than relying on global settings.
- Error classes are exposed through the
errorsnamespace, with new validation, notation, evaluation and import errors. - The bundle paths have changed from
lib/todist/. Check any imports that refer directly to a bundle file rather than the package name.
See Configuring rolls, Customisation, Handling errors and Get started.
Notation and output changes โ
MathJS has been removed. Maths follows native JavaScript number semantics, except for floored modulo; rounding no longer snaps to nearby integers, halfway values round towards positive infinity, and modulo by zero and non-real powers are invalid. See Maths and the migration guide.
Fractional computed dice quantities are rejected instead of truncated. For example,
(3/2)d6is invalid; use an explicit rounding function if you intend to roll an integer quantity.Target success and failure conditions must be written together, and the last matching condition determines the score.
Critical success and failure markers in the default text output have changed from
**and__tocsandcf. Target success and failure markers can now repeat to indicate a weighted score.
New features โ
More expressive notation โ
Expressions can be used to calculate the quantity of dice, the number of sides and the number of results to keep or drop. These calculations can include other dice rolls, functions and roll groups.
Comparisons and ternary conditionals allow notation to make decisions based on evaluated values, while variables allow you to supply data from your application without constructing new notation strings.
| Example | What it does |
|---|---|
(d4)d6 | Roll a d4 to determine how many d6s to roll. |
d(2d4) | Roll two d4s to determine the number of sides of another die. |
4d6kh(d4) | Keep a number of the highest results determined by a d4. |
(max(4,2))d10 | Use the larger of two values as the dice quantity. |
(d20+5>=15) | Evaluate a comparison to 1 or 0. |
((d20)>=15)?(2d6):(0) | Conditionally roll damage based on an expression comparison. |
d20+$character.attackBonus | Add a value supplied by your application. |
Try these expressions and experiment with your own combinations in the dice playground.
See Maths, Comparisons and ternaries and Variables.
Custom dice โ
You can define dice with arbitrary numeric faces, including repeated faces to give some values a greater probability of being rolled. Ranges support custom minimums, maximums and step sizes.
| Example | What it does |
|---|---|
d{1,1,2,5} | Roll a die with four faces, two of which are 1. |
d{-3...3} | Roll a value from -3 to 3. |
d{0:0.5:2} | Roll one of 0, 0.5, 1, 1.5 or 2. |
For more specialised game mechanics, you can also register your own die factories and provide custom rolling behaviour.
See Dice notation and Custom dice.
New modifier capabilities โ
- Weighted targets: count some successes or failures more heavily than others. For example,
4d10>=8>=10:2f=1:2counts a roll of 10 as two successes and a roll of 1 as two failures. - Repeating modifier limits: limit explosions, re-rolls or unique retries, for example
d6!3. - Multiple dice per trigger: generate several dice on an explosion or re-roll, for example
d6!2:3ord6ro:3. - Matching-batch explosions: use
2d6!mto roll another batch whenever all the dice in a batch match. - Map modifier: transform individual dice or immediate group member totals using expressions, including variables, conditions and nested dice rolls.
- Calculated keep/drop counts: use an expression instead of a fixed number when choosing how many results to keep or drop.
See Modifiers. You can also configure modifier execution order and replace built-in modifier behaviour using the modifier registry.
Parsing and building expressions โ
The new abstract syntax tree (AST) separates parsing from evaluation. Parse notation without rolling dice, inspect the resulting expression, or construct rolls programmatically using the AST builders.
import { Roll, ast } from '@dice-roller/rpg-dice-roller';
const expression = ast.binary('+', ast.pool(2, 6), 3);
const roll = new Roll(expression);
console.log(roll.total);This is particularly useful for graphical notation builders, reusable game mechanics and custom dice that cannot be expressed using the built-in notation syntax.
See Parsing and building expressions.
Richer roll results โ
The evaluated result tree follows the structure of the original expression. Each pool includes information about the resolved die, the original and modified values of its results, and how each result contributes to the total.
This makes it easier to build interfaces that distinguish die types, display modifier effects or inspect calculations within complex expressions.
See Working with results.
Presenters โ
Result formatting is now separate from rolling. The built-in text presenter supports configurable modifier symbols and other formatting options, and you can implement your own presenter for any output format.
First-party SVG and terminal presenters are also available for displaying results graphically or in a terminal.
See Presenters.
Random engines and external dice sources โ
Choose a random engine by name, supply a seed or register your own engine. You can configure engines for a roller or override them for individual rolls.
The new drawDie option also lets an external source supply individual die values as they're needed, while the library continues to apply modifiers and calculate totals.
This allows integrations with 3D dice rollers, remote dice services or prompts for physical dice results. External sources can be synchronous or asynchronous; ordinary rolls remain synchronous.
See Random number generator and External dice sources.
Restoring finished results โ
In addition to importing complete, versioned roll snapshots, v6 supports concise imports that specify notation and finished dice results. The library reconstructs the result tree and calculates totals without rolling again.
For concise imports, modifier effects must already be included in the supplied results. Use an external dice source instead if you want the library to apply modifiers to supplied die draws.
Fixes and behaviour changes โ
More useful errors โ
Invalid notation produces clearer diagnostics, including source locations for syntax errors. NotationError.format() can display the offending source line with a caret pointing to the problem.
For example, invalid quantities such as 0d6 now produce a more useful error. Computed quantities that evaluate to zero are supported, allowing expressions to determine whether a pool rolls any dice.
See Handling errors.
Improved roll statistics โ
Minimum and maximum totals now account for supported arithmetic and modifiers. For example, 10-d6 correctly reports bounds of 4 and 9.
Average calculations account for weighted die faces, target scoring and standalone Keep and Drop modifiers. For example, 2d20kh1 has an average of 13.825, rather than the midpoint of 10.5.
Unsupported calculations return null instead of potentially misleading estimates. No additional dice are rolled to calculate these statistics.
See Calculated totals.
Limits on additional rolls โ
Repeating modifiers share a configurable per-pool budget for additional dice draws, as well as their iteration limits. When the budget is exhausted, they stop generating new dice and retain the results reached so far.
This helps control potentially large branching explosions and re-rolls, without imposing a single budget on the whole expression.
See Roll limits.
Further reading โ
- Migrating from v5 to v6 โ update an existing application.
- Get started โ install and load v6.
- Usage โ learn the new API.
- Notation โ explore dice types, modifiers and expressions.
- Customisation โ adapt the library to your application.
- v6 release discussion โ development discussion and release tracking.