#### Digital Dice Rolling: Dice Notation

The notebook can include markdown that rolls digital dice. You can roll dice with any number of sides

``rollable([dice=]dicenotation,[dicelabel=label text,label=label text])``

If the only field used is `dice=`, the field label can be omitted, so `rollable(dice=1d20+2)` is can be shortened to `rollable(1d20+2)`.

## Dice Notation

Dice rolls are given in the form `AdX`A and X are variables, separated by the letter d, which stands for die or dice. The letter d is lower-case.

• A is the number of dice to be rolled.
• X is the number of faces of each dice.

To this basic notation, an additive modifier can be appended, yielding expressions of the form AdX+B. The plus sign can be replaced by a minus sign (“-“) to indicate subtraction. B is a number to be added to the sum of the rolls. So, `1d20+10` would indicate a roll of a single 20-sided die with 10 being added to the result. These expressions can also be chained (e.g. `2d6+1d8+4`).

Each dice group is resolved and the total re-calculated as it is processed left-to-right. No order of operations are used to calculate the final result.

Dice notation is usable in `rollable()` markdown as well as the dice rolling panel.

### Examples

`1d20` will roll a 20-sided die and return the result.

`2d6+4` will roll 2 6-sided dice, add them together and add 4.

### Keep/Drop Highest/Lowest

Some systems allow for rolling multiple times and picking the highest or lowest dice from all those rolled. This can be accomplished with by adding the following the the dice notation

notationABX

• A is either `k` for keep or `d` for drop
• B is either `h` for highest or `l` for lowest
• X is the number of dice to keep or drop

### Examples

`4d6dl1` will roll 4 6-sided dice, drop the lowest, and add the remaining 3 together. This is functionally equivalent to `4d6kh3` (roll 4d6, keep the highest 3, add them together).

## Open-ended rolling, exploding dice, and penetration rolls

Several games use mechanics that allow one or more dice to be rerolled (often a die that rolls the highest possible number), with each successive roll being added to the total.

The notation for exploding dice is to use an exclamation point: `AdX!` or 6d6!.

## number() and mod5e() is Statblocks

As well as the standalone `rollable()` syntax, `number()` and `mod5e()` now also have the `dice=` and `dicelabel=` properties to allow dice to be rolled based on the numerical value of the field. This allows you to create a number that is editable via the UI then have that number used in the roll. To use the selected number in the roll, replace any of `A`, `X` or `B` in `AdX+B` with the character `n` e.g. `1d20+n` or `2dn+4`.

### Examples

`Damage 1d6 + number(name=damage,label=Strength,value=4,dice=1d6+n,dicelabel=Damage)` Rolls `1d6+n` where `n` is the `numer()` value selected.

`Strength number(name=str,label=Strength,value=12) (mod5e(show_symbol,value=str,dice=1d20+n,dicelabel=Strength Roll))` Rolls `1d20+n` where n is the `mod5e()` value calculated from the `number()` selected.

## Rolling

When the dice are rolled, the result will appear at the top of the page.

1. The title can be customised with the `dicelabel` option.
2. Shows the individual dice rolls. Groups will be shown in parenthesis, e.g. `2d6 + 2d4 + 2` will show the `2d6` grouped together, the `2d4` grouped together and the `+ 2` by itself. Max die rolls are highlighted green, min die rolls are highlighted red. If you specify keep/drop high/low then the rolls kept will be highlighted in green and the rolls dropped will be greyed and crossed out.
3. The final total.
4. The original roll notation.

You can close the notification by clicking the X button or swiping it away on a touch screen. Rolling again will also update the notification. There is no history of rolls kept.