Variables New in v6 ​
Variables let you reuse the same notation with different values, such as each character's attack bonus, strength, or fire resistance.
You can supply your own values when you make a roll, or use the built-in variables.
Variables you supply ​
Notation: $name
If you have supplied your own data, then you can use it in notation when you roll.
Using this example data:
{
bonus: 3,
character: { attackBonus: 2, isPoisoned: true }
}This adds the value of bonus to a d20 roll:
d20+$bonus: [18]+$bonus = 21Use a dot to refer to a value inside a nested object:
d20+$character.attackBonus: [18]+$character.attackBonus = 20Variables can hold finite numbers or booleans. The dice roller treats true as 1 and false as 0, so $character.isPoisoned evaluates to 1 with the example data above. A reference such as $character.defence gives an error if the roll tries to read it and no value was supplied.
See Variable data for how to pass these values to a roll.
Using variables in expressions ​
You can use variables in arithmetic, functions, comparisons and ternaries, as well as in calculated quantities and sides.
(max($bonus+$character.attackBonus, 4))d10With the example data above, max(3 + 2, 4) gives 5, so the roller rolls five d10s.
Built-in variables ​
Notation: $$name
The dice roller sets built-in variables as it evaluates the notation. Use two dollar signs to refer to a built-in variable and one for a value you supply.
Ternary branches ​
Notation: $$condition
Inside the selected branch of a ternary, $$condition holds the numeric result of the condition.
You can use it in either branch. If a branch contains another ternary, $$condition in the inner ternary’s selected branch refers to the inner condition. Reading $$condition outside a ternary branch gives an error.
((d6) >= 4) ? ($$condition + 2) : (4 - $$condition)The comparison gives 1 on a roll of 4 or higher, so the first branch gives 3. On a lower roll it gives 0, so the second branch gives 4.
An arithmetic condition can also be reused without rolling its dice again:
(d6 - 1) ? ($$condition + 2) : (0)If the die rolls 4, the condition evaluates to 3 and the first branch gives 5. If the die rolls 1, the condition is 0 and the second branch gives 0.
Map expressions ​
Inside a Map modifier, the following built-in variables are available:
| Variable | Value |
|---|---|
$$value | The current die value or immediate group member total before mapping. |
$$index | The zero-based position of the item being mapped. |
$$count | The number of items being mapped, including generated dice in a pool. |
4d6map(($$index = $$count - 1) ? ($$value * 2) : ($$value))This doubles only the last result. The map variables remain available inside nested ternary branches, alongside $$condition. Nested maps shadow the outer map variables while evaluating their own expressions, then restore the outer scope.
4d6map($$value + 2d8map($$value + $$index) + $$index)The variables inside the inner map refer to the d8 results; the final $$index refers to the outer d6 result. Reading a map variable outside its scope gives an error, just as with $$condition outside its ternary scope.