#
Quick Start
#
Download the package to your project
Navigate to your projects root directory and open the console. From the command line run:
npm i @mateo-wallace/rpg-dice-js
#
Require rpg-dice-js and call the roll() function
Once you have the package installed locally simply require the package along with the roll function and type an input.
const { roll } = require("rpg-dice-js");
const exampleInput = "1d20 + 5";
// the roll function responds with an Object
const object = roll(exampleInput);
// to get a specific item within the object add the key after roll
const result = roll(exampleInput).result;
Just using roll responds with an object of various response keys. In order to target a specific key instead of simpling using roll("1d20")
use roll("1d20").key
where key
is the name of the object key you wish to access.
#
Output
Example outputs of using console.log()
on the object
and result
variables
{
"ok": true,
"input": "1d20 + 5",
"result": "1d20 (8) + 5",
"total": 13,
"resultNoDice": "(8) + 5",
"prefab": "Input: 1d20 + 5 | Result: 1d20 (8) + 5 | Total: 13",
"inputArray": ["1d20", "+", "5"],
"resultArray": ["1d20", "(8)", "+", "5"],
"resultNoDiceArray": ["(8)", "+", "5"],
"totalCrit": 21
}
"1d20 (8) + 5"
#
More Info
For more in depth information on the roll()
function or for information on how to use the Dice({})
class to customize the dice roller, continue reading.