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:
TypeError
Result 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']);
number
rollResult.calculationValue ⇒ 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
Param | Type |
---|---|
value | number |
number
rollResult.initialValue ⇒ 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
string
rollResult.modifierFlags ⇒ The visual flags for the modifiers that affect the roll.
Kind: instance property of RollResult
See: modifiers
Set.<string>
rollResult.modifiers ⇒ 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
Param | Type |
---|---|
value | Array.<string> | Set.<string> |
Example
rollResult.modifiers = ['explode', 're-roll'];
boolean
rollResult.useInTotal ⇒ 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 |
number
rollResult.value ⇒ 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 finiteTypeError
value is invalid
Param | Type |
---|---|
value | number |
Object
rollResult.toJSON() ⇒ Return an object for JSON serialising.
This is called automatically when JSON encoding the object.
Kind: instance method of RollResult
string
rollResult.toString() ⇒ Return the String representation of the object.
This is called automatically when casting the object to a string.
Kind: instance method of RollResult