RollResult

RollResult

A RollResult represents the value and applicable modifiers for a single die roll

TIP

You will probably not need to create your own RollResult instances, unless you're importing rolls, but RollResult objects will be returned when rolling dice.

Kind: global class

new RollResult(value, [modifiers], [useInTotal])

Create a RollResult instance.

value can be a number, or an object containing a list of different values. This allows you to specify the initialValue, value and calculationValue with different values.

Throws:

  • TypeError Result value, calculation value, or modifiers are invalid
ParamTypeDefaultDescription
valuenumber | ObjectThe value rolled
[value.value]numberThe value with modifiers applied
[value.initialValue]numberThe initial, unmodified value rolled
[value.calculationValue]numberThe value used in calculations
[modifiers]Array.<string> | Set.<string>[]List of modifier names that affect this roll
[useInTotal]booleantrueWhether to include the roll value when calculating totals

Example (Numerical value)

const result = new RollResult(4);

Example (Object value)

// must provide either `value` or `initialValue`
// `calculationValue` is optional.
const result = new RollResult({
  value: 6,
  initialValue: 4,
  calculationValue: 8,
});

Example (With modifiers)

const result = new RollResult(4, ['explode', 'critical-success']);

rollResult.calculationValue ⇒ number

The value to use in calculations. This may be changed by modifiers.

Kind: instance property of RollResult

rollResult.calculationValue

Set the value to use in calculations.

Kind: instance property of RollResult
Throws:

  • TypeError value is invalid
ParamType
valuenumber

rollResult.initialValue ⇒ number

The initial roll value before any modifiers.

Not used for calculations and is just for reference. You probably want value instead.

Kind: instance property of RollResult
See: value

rollResult.modifierFlags ⇒ string

The visual flags for the modifiers that affect the roll.

Kind: instance property of RollResult
See: modifiers

rollResult.modifiers ⇒ Set.<string>

The names of modifiers that affect the roll.

Kind: instance property of RollResult

rollResult.modifiers

Set the modifier names that affect the roll.

Kind: instance property of RollResult
Throws:

  • TypeError modifiers must be a Set or array of modifier names
ParamType
valueArray.<string> | Set.<string>

Example

rollResult.modifiers = ['explode', 're-roll'];

rollResult.useInTotal ⇒ boolean

Whether to use the value in total calculations or not.

Kind: instance property of RollResult

rollResult.useInTotal

Set whether to use the value in total calculations or not.

Kind: instance property of RollResult

ParamType
valueboolean

rollResult.value ⇒ number

Value of the roll after modifiers have been applied.

Kind: instance property of RollResult

rollResult.value

Set the roll value.

Kind: instance property of RollResult
Throws:

  • RangeError value must be finite
  • TypeError value is invalid
ParamType
valuenumber

rollResult.toJSON() ⇒ Object

Return an object for JSON serialising.

This is called automatically when JSON encoding the object.

Kind: instance method of RollResult

rollResult.toString() ⇒ string

Return the String representation of the object.

This is called automatically when casting the object to a string.

Kind: instance method of RollResult