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
- RollResult
- new RollResult(value, [modifiers], [useInTotal])
- .calculationValue ⇒
number - .calculationValue
- .initialValue ⇒
number - .modifierFlags ⇒
string - .modifiers ⇒
Set.<string> - .modifiers
- .useInTotal ⇒
boolean - .useInTotal
- .value ⇒
number - .value
- .toJSON() ⇒
Object - .toString() ⇒
string
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:
TypeErrorResult value, calculation value, or modifiers are invalid
| Param | Type | Default | Description |
|---|---|---|---|
| value | number | Object | The value rolled | |
| [value.value] | number | The value with modifiers applied | |
| [value.initialValue] | number | The initial, unmodified value rolled | |
| [value.calculationValue] | number | The value used in calculations | |
| [modifiers] | Array.<string> | Set.<string> | [] | List of modifier names that affect this roll |
| [useInTotal] | boolean | true | Whether 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:
TypeErrorvalue is invalid
| Param | Type |
|---|---|
| value | number |
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:
TypeErrormodifiers must be a Set or array of modifier names
| Param | Type |
|---|---|
| value | Array.<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
| Param | Type |
|---|---|
| value | boolean |
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:
RangeErrorvalue must be finiteTypeErrorvalue is invalid
| Param | Type |
|---|---|
| value | number |
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