The string formula to parse
The data object against which to parse attributes within the formula
Optionaloptions: 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
StaticCHAT_The HTML template path used to render a complete Roll object to the chat log
Static ReadonlyDICE_Dice Configuration setting name.
StaticMATH_A Proxy environment for safely evaluating a string using only available Math functions
StaticRESOLVERSA mapping of Roll instances to currently-active resolvers.
StaticTOOLTIP_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.
StaticdefaultGet the default configured Roll class.
StaticresolverRetrieve 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.
OptionalmultiplyNumeric: 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
Optionaloptions: {Options which inform how the Roll is evaluated
OptionalallowInteractive?: booleanIf false, force the use of non-interactive rolls and do not prompt the user to make manual rolls.
OptionalallowStrings?: booleanIf true, string terms will not cause an error to be thrown during evaluation.
Optionalmaximize?: booleanMaximize the result, obtaining the largest possible value.
Optionalminimize?: booleanMinimize the result, obtaining the smallest possible value.
The evaluated Roll instance
Execute the Roll synchronously, replacing dice and evaluating the total result.
Optionaloptions: {OptionalallowStrings?: booleanIf true, string terms will not cause an error to be thrown during evaluation.
Optionalmaximize?: booleanMaximize the result, obtaining the largest possible value.
Optionalminimize?: booleanMinimize the result, obtaining the smallest possible value.
Optionalstrict?: 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
Optionaloptions: { flavor?: string; isPrivate?: boolean; template?: string } = {}Options which affect how the Roll is rendered
Optionalflavor?: stringFlavor text to include
OptionalisPrivate?: booleanIs the Roll displayed privately?
Optionaltemplate?: 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.
Optionaloptions: 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.
Optionaloptions: {Additional options to configure how the link is constructed.
Optionalattrs?: Record<string, string>Attributes to set on the link.
Optionalclasses?: string[]Additional classes to add to the link. The classes inline-roll
and inline-result are added by default.
Optionaldataset?: Record<string, string>Custom data attributes to set on the link.
Optionalicon?: stringA font-awesome icon class to use as the icon instead of a d20.
Optionallabel?: 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
Optionaloptions: { create?: boolean; rollMode?: string } = {}Additional options which modify the created message.
Optionalcreate?: booleanWhether to automatically create the chat message, or only return the prepared chatData object.
OptionalrollMode?: 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_evaluateProtectedEvaluate the roll asynchronously.
Optionaloptions: {Options which inform how evaluation is performed
OptionalallowInteractive?: booleanIf false, force the use of digital rolls and do not prompt the user to make manual rolls.
OptionalallowStrings?: booleanIf true, string terms will not cause an error to be thrown during evaluation.
Optionalmaximize?: booleanForce the result to be maximized
Optionalminimize?: booleanForce the result to be minimized
Protected_evaluateASTAsyncProtectedEvaluate an AST asynchronously.
The root node or term.
Optionaloptions: { allowStrings?: boolean; maximize?: boolean; minimize?: boolean } = {}Options which inform how evaluation is performed
OptionalallowStrings?: booleanIf true, string terms will not cause an error to be thrown during evaluation.
Optionalmaximize?: booleanForce the result to be maximized
Optionalminimize?: booleanForce the result to be minimized
Protected_evaluateASTSyncProtectedEvaluate an AST synchronously.
The root node or term.
Optionaloptions: {Options which inform how evaluation is performed
OptionalallowStrings?: booleanIf true, string terms will not cause an error to be thrown during evaluation.
Optionalmaximize?: booleanForce the result to be maximized
Optionalminimize?: booleanForce the result to be minimized
Optionalstrict?: booleanThrow an error if encountering a term that cannot be synchronously evaluated.
Protected_evaluateProtectedEvaluate the roll synchronously.
Optionaloptions: {Options which inform how evaluation is performed
OptionalallowStrings?: booleanIf true, string terms will not cause an error to be thrown during evaluation.
Optionalmaximize?: booleanForce the result to be maximized
Optionalminimize?: booleanForce the result to be minimized
Optionalstrict?: booleanThrow an error if encountering a term that cannot be synchronously evaluated.
Protected_evaluateProtectedSafely evaluate the final total result for the Roll using its component terms.
The evaluated total
Protected_prepareProtected_prepareProtectedPrepare 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_classifyInternalClassify a remaining string term into a recognized RollTerm class
A classified RollTerm instance
StaticcollapseCollapse an expanded inline roll to conceal its tooltip.
The inline-roll button
StaticcreateA factory method which constructs a Roll instance using the default configured Roll class.
The formula used to create the Roll instance
Optionaldata: object = {}The data object which provides component data for the formula
Optionaloptions: object = {}Additional options which modify or describe this Roll
The constructed Roll instance
StaticexpandExpand an inline roll element to display its contained dice result as a tooltip.
The inline-roll button
StaticfromRecreate a Roll instance using a provided data object
Unpacked data representing the Roll
A reconstructed Roll instance
StaticfromJSONRecreate a Roll instance using a provided JSON string
Serialized JSON data representing the Roll
A reconstructed Roll instance
StaticfromStaticgetTransform 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
StaticidentifyStaticinstantiateASTInstantiate the nodes in an AST sub-tree into RollTerm instances.
The root of the AST sub-tree.
StaticparseParse 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.
StaticregisterRegister 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.
StaticreplaceReplace 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
Optionaloptions: { missing?: string; warn?: boolean } = {}Options which modify formula replacement
Optionalmissing?: stringThe value that should be assigned to any unmatched keys. If null, the unmatched key is left as-is.
Optionalwarn?: booleanDisplay a warning notification when encountering an un-matched key.
StaticsafeA sandbox-safe evaluation function to execute user-input code with access to scoped Math methods.
The input string expression
The numeric evaluated result
StaticsimplifyAfter 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
StaticsimulateSimulate a roll and evaluate the distribution of returned results
The Roll expression to simulate
The number of simulations
The rolled totals
StaticvalidateValidate 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