The string formula to parse
The data object against which to parse attributes within the formula
Optional
options: RollOptions = {}Options modifying or describing the Roll
Internal
_diceAn array of inner DiceTerms that were evaluated as part of the Roll evaluation
Internal
_evaluatedTrack whether this Roll instance has been evaluated or not. Once evaluated the Roll is immutable.
Internal
_formulaStore the original cleaned formula for the Roll, prior to any internal evaluation or simplification
Internal
_resolverA reference to the RollResolver app being used to externally resolve this Roll.
Internal
_rootA reference to the Roll at the root of the evaluation tree.
Internal
_totalCache the numeric total generated through evaluation of the Roll.
The original provided data object which substitutes into attributes of the roll formula.
Options modifying or describing the Roll
The identified terms of the Roll
Static
CHAT_The HTML template path used to render a complete Roll object to the chat log
Static
Readonly
DICE_Dice Configuration setting name.
Static
MATH_A Proxy environment for safely evaluating a string using only available Math functions
Static
RESOLVERSA mapping of Roll instances to currently-active resolvers.
Static
TOOLTIP_The HTML template used to render an expanded Roll tooltip to the chat log
Return an Array of the individual DiceTerm instances contained within this Roll.
Return a standardized representation for the displayed formula associated with this Roll.
Whether this Roll contains entirely deterministic terms or whether there is some randomness.
Return the arbitrary product of evaluating this Roll.
The resulting arithmetic expression after rolls have been evaluated
Return the total result of the Roll expression if it has been evaluated.
Static
defaultGet the default configured Roll class.
Static
resolverRetrieve the appropriate resolver implementation based on the user's configuration.
Alter the Roll expression by adding or multiplying the number of dice which are rolled
A factor to multiply. Dice are multiplied before any additions.
A number of dice to add. Dice are added after multiplication.
Optional
multiplyNumeric: boolean = {}Apply multiplication factor to numeric scalar terms
The altered Roll expression
Clone the Roll instance, returning a new Roll instance that has not yet been evaluated.
Execute the Roll asynchronously, replacing dice and evaluating the total result
Optional
options: {Options which inform how the Roll is evaluated
Optional
allowInteractive?: booleanIf false, force the use of non-interactive rolls and do not prompt the user to make manual rolls.
Optional
allowStrings?: booleanIf true, string terms will not cause an error to be thrown during evaluation.
Optional
maximize?: booleanMaximize the result, obtaining the largest possible value.
Optional
minimize?: booleanMinimize the result, obtaining the smallest possible value.
The evaluated Roll instance
Execute the Roll synchronously, replacing dice and evaluating the total result.
Optional
options: {Optional
allowStrings?: booleanIf true, string terms will not cause an error to be thrown during evaluation.
Optional
maximize?: booleanMaximize the result, obtaining the largest possible value.
Optional
minimize?: booleanMinimize the result, obtaining the smallest possible value.
Optional
strict?: booleanThrow an Error if the Roll contains non-deterministic terms that cannot be evaluated synchronously. If this is set to false, non-deterministic terms will be ignored.
The evaluated Roll instance.
Render the tooltip HTML for a Roll instance
The rendered HTML tooltip as a string
Propagate flavor text across all terms that do not have any.
The flavor text.
Render a Roll instance to HTML
Optional
options: { flavor?: string; isPrivate?: boolean; template?: string } = {}Options which affect how the Roll is rendered
Optional
flavor?: stringFlavor text to include
Optional
isPrivate?: booleanIs the Roll displayed privately?
Optional
template?: stringA custom HTML template path
The rendered HTML template as a string
Create a new Roll object using the original provided formula and data. Each roll is immutable, so this method returns a new Roll instance using the same data.
Optional
options: object = {}Evaluation options passed to Roll#evaluate
A new Roll object, rolled using the same formula and data
Recompile the formula string that represents this Roll instance from its component terms.
The re-compiled formula
Alias for evaluate.
Options passed to Roll#evaluate
Construct an inline roll link for this Roll.
Optional
options: {Additional options to configure how the link is constructed.
Optional
attrs?: Record<string, string>Attributes to set on the link.
Optional
classes?: string[]Additional classes to add to the link. The classes inline-roll
and inline-result
are added by default.
Optional
dataset?: Record<string, string>Custom data attributes to set on the link.
Optional
icon?: stringA font-awesome icon class to use as the icon instead of a d20.
Optional
label?: stringA custom label for the total.
Represent the data of the Roll as an object suitable for JSON serialization.
Structured data which can be serialized into JSON
Transform a Roll instance into a ChatMessage, displaying the roll result. This function can either create the ChatMessage directly, or return the data object that will be used to create.
The data object to use when creating the message
Optional
options: { create?: boolean; rollMode?: string } = {}Additional options which modify the created message.
Optional
create?: booleanWhether to automatically create the chat message, or only return the prepared chatData object.
Optional
rollMode?: stringThe template roll mode to use for the message from CONFIG.Dice.rollModes
A promise which resolves to the created ChatMessage document if create is true, or the Object of prepared chatData otherwise.
Protected
_evaluateProtected
Evaluate the roll asynchronously.
Optional
options: {Options which inform how evaluation is performed
Optional
allowInteractive?: booleanIf false, force the use of digital rolls and do not prompt the user to make manual rolls.
Optional
allowStrings?: booleanIf true, string terms will not cause an error to be thrown during evaluation.
Optional
maximize?: booleanForce the result to be maximized
Optional
minimize?: booleanForce the result to be minimized
Protected
_evaluateASTAsyncProtected
Evaluate an AST asynchronously.
The root node or term.
Optional
options: { allowStrings?: boolean; maximize?: boolean; minimize?: boolean } = {}Options which inform how evaluation is performed
Optional
allowStrings?: booleanIf true, string terms will not cause an error to be thrown during evaluation.
Optional
maximize?: booleanForce the result to be maximized
Optional
minimize?: booleanForce the result to be minimized
Protected
_evaluateASTSyncProtected
Evaluate an AST synchronously.
The root node or term.
Optional
options: {Options which inform how evaluation is performed
Optional
allowStrings?: booleanIf true, string terms will not cause an error to be thrown during evaluation.
Optional
maximize?: booleanForce the result to be maximized
Optional
minimize?: booleanForce the result to be minimized
Optional
strict?: booleanThrow an error if encountering a term that cannot be synchronously evaluated.
Protected
_evaluateProtected
Evaluate the roll synchronously.
Optional
options: {Options which inform how evaluation is performed
Optional
allowStrings?: booleanIf true, string terms will not cause an error to be thrown during evaluation.
Optional
maximize?: booleanForce the result to be maximized
Optional
minimize?: booleanForce the result to be minimized
Optional
strict?: booleanThrow an error if encountering a term that cannot be synchronously evaluated.
Protected
_evaluateProtected
Safely evaluate the final total result for the Roll using its component terms.
The evaluated total
Protected
_prepareProtected
_prepareProtected
Prepare the data structure used for the Roll. This is factored out to allow for custom Roll classes to do special data preparation using provided input.
Provided roll data
The prepared data object
Static
_classifyInternal
Classify a remaining string term into a recognized RollTerm class
A classified RollTerm instance
Static
collapseCollapse an expanded inline roll to conceal its tooltip.
The inline-roll button
Static
createA factory method which constructs a Roll instance using the default configured Roll class.
The formula used to create the Roll instance
Optional
data: object = {}The data object which provides component data for the formula
Optional
options: object = {}Additional options which modify or describe this Roll
The constructed Roll instance
Static
expandExpand an inline roll element to display its contained dice result as a tooltip.
The inline-roll button
Static
fromRecreate a Roll instance using a provided data object
Unpacked data representing the Roll
A reconstructed Roll instance
Static
fromJSONRecreate a Roll instance using a provided JSON string
Serialized JSON data representing the Roll
A reconstructed Roll instance
Static
fromStatic
getTransform an array of RollTerm objects into a cleaned string formula representation.
An array of terms to represent as a formula
The string representation of the formula
Static
identifyStatic
instantiateASTInstantiate the nodes in an AST sub-tree into RollTerm instances.
The root of the AST sub-tree.
Static
parseParse a formula expression using the compiled peggy grammar.
The original string expression to parse.
A data object used to substitute for attributes in the formula.
Static
registerRegister an externally-fulfilled result with an active RollResolver.
The fulfillment method.
The die denomination being fulfilled.
The obtained result.
Whether the result was consumed. Returns undefined if no resolver was available.
Static
replaceReplace referenced data attributes in the roll formula with values from the provided data. Data references in the formula use the @attr syntax and would reference the corresponding attr key.
The original formula within which to replace
The data object which provides replacements
Optional
options: { missing?: string; warn?: boolean } = {}Options which modify formula replacement
Optional
missing?: stringThe value that should be assigned to any unmatched keys. If null, the unmatched key is left as-is.
Optional
warn?: booleanDisplay a warning notification when encountering an un-matched key.
Static
safeA sandbox-safe evaluation function to execute user-input code with access to scoped Math methods.
The input string expression
The numeric evaluated result
Static
simplifyAfter parenthetical and arithmetic terms have been resolved, we need to simplify the remaining expression. Any remaining string terms need to be combined with adjacent non-operators in order to construct parsable terms.
An array of terms which is eligible for simplification
An array of simplified terms
Static
simulateSimulate a roll and evaluate the distribution of returned results
The Roll expression to simulate
The number of simulations
The rolled totals
Static
validateValidate that a provided roll formula can represent a valid
A candidate formula to validate
Is the provided input a valid dice formula?
An interface and API for constructing and evaluating dice rolls. The basic structure for a dice roll is a string formula and an object of data against which to parse it.
Example: Attack with advantage