ResultGroup
ResultGroup
A collection of results and expressions. Usually used to represent the results of a RollGroup instance.
This can contain ResultGroup, RollResults, operators, and plain numbers.
TIP
You will probably not need to create your own ResultGroup instances, unless you're importing rolls, but ResultGroup objects will be returned when rolling group rolls.
Kind: global class
Since: 4.5.0
- ResultGroup
- new ResultGroup([results], [modifiers], [isRollGroup], [useInTotal])
- .calculationValue ⇒
number - .calculationValue
- .isRollGroup ⇒
boolean - .isRollGroup
- .length ⇒
number - .modifierFlags ⇒
string - .modifiers ⇒
Set.<string> - .modifiers
- .results ⇒
Array.<(ResultGroup|RollResults|number|string)> - .results
- .useInTotal ⇒
boolean - .useInTotal
- .value ⇒
number - .addResult(value)
- .toJSON() ⇒
Object - .toString() ⇒
string
new ResultGroup([results], [modifiers], [isRollGroup], [useInTotal])
Create a ResultGroup instance.
Throws:
TypeErrorRolls must be an array
| Param | Type | Default | Description |
|---|---|---|---|
| [results] | Array.<(ResultGroup|RollResults|number|string)> | [] | The results and expressions |
| [modifiers] | Array.<string> | Set.<string> | [] | List of modifier names that affect the group |
| [isRollGroup] | boolean | false | Whether the result group represents a roll group or not |
| [useInTotal] | boolean | true | Whether to include the group's value when calculating totals |
Example (Normal roll: `4d6+2d10`)
const results = new ResultGroup([
new RollResults([3, 5, 4, 2]),
'+',
new RollResults([4, 8]),
]);
Example (Roll group: `{4d6+2d10/2, 5d6/2d%}`)
const results = new ResultGroup([
new ResultGroup([
new RollResults([3, 5, 4, 2]),
'+',
new RollResults([4, 8]),
'/',
2,
]),
new ResultGroup([
new RollResults([3, 3, 5, 2, 4]),
'/',
new RollResults([87, 46]),
]),
]);
resultGroup.calculationValue ⇒ number
The value to use in calculations. This may be changed by modifiers.
Kind: instance property of ResultGroup
resultGroup.calculationValue
Set the value to use in calculations.
Kind: instance property of ResultGroup
Throws:
TypeErrorvalue is invalid
| Param | Type |
|---|---|
| value | number |
resultGroup.isRollGroup ⇒ boolean
Whether the result group represents a roll group or not.
Kind: instance property of ResultGroup
Returns: boolean - true if it is a roll group, false otherwise
resultGroup.isRollGroup
Set whether the result group represents a roll group or not.
Kind: instance property of ResultGroup
| Param | Type |
|---|---|
| value | boolean |
resultGroup.length ⇒ number
The number of results.
Kind: instance property of ResultGroup
resultGroup.modifierFlags ⇒ string
The visual flags for the modifiers that affect the group.
Kind: instance property of ResultGroup
See: modifiers
resultGroup.modifiers ⇒ Set.<string>
The modifier names that affect the group.
Kind: instance property of ResultGroup
resultGroup.modifiers
Set the modifier names that affect the group.
Kind: instance property of ResultGroup
Throws:
TypeErrormodifiers must be a Set or array of modifier names
| Param | Type |
|---|---|
| value | Array.<string> | Set.<string> |
Example
resultGroup.modifiers = ['drop', 'target-success'];
resultGroup.results ⇒ Array.<(ResultGroup|RollResults|number|string)>
List of results.
Kind: instance property of ResultGroup
resultGroup.results
Set the results.
Kind: instance property of ResultGroup
Throws:
TypeErrorResults must be an array
| Param | Type |
|---|---|
| results | Array.<(ResultGroup|RollResults|number|string)> |
resultGroup.useInTotal ⇒ boolean
Whether to use the value in total calculations or not.
Kind: instance property of ResultGroup
resultGroup.useInTotal
Set whether to use the value in total calculations or not.
Kind: instance property of ResultGroup
| Param | Type |
|---|---|
| value | boolean |
resultGroup.value ⇒ number
The total value of all the results after modifiers have been applied.
Kind: instance property of ResultGroup
resultGroup.addResult(value)
Add a single result to the list.
Kind: instance method of ResultGroup
Throws:
TypeErrorValue type is invalid
| Param | Type |
|---|---|
| value | ResultGroup | RollResults | number | string |
resultGroup.toJSON() ⇒ Object
Return an object for JSON serialising.
This is called automatically when JSON encoding the object.
Kind: instance method of ResultGroup
resultGroup.toString() ⇒ string
Return the String representation of the object.
This is called automatically when casting the object to a string.
Kind: instance method of ResultGroup