Constructor
new Table(outFunction)
- Source:
Example
let table = new Table();
table.add(50, 'heads')
table.add(50, 'tails');
table.get();
=> 'heads'
Parameters:
| Name | Type | Description |
|---|---|---|
outFunction |
function | A function to run on values supplied to the add method. For example, you might create a function to convert item names to true Item objects, as a convenience when building the table. |
Methods
add(percentOrStartRoll, endRollopt, object)
- Description:
Add something to this table. You can either specify the specific percentage that this element should be selected, or you can provide the range of die roll numbers (this latter approach is easier when you're adapting an existing pen-and-paper table).
The percentages must add up to 100% (or 100 on 1d100).
- Source:
Example
let table = new Table();
table.add(50, object); // will occur 50% of the time
table.add(1, 70, object); // Will occur 70% of the time, on a roll of 1 to 70
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
percentOrStartRoll |
Number | % chance occurrence of 100%, or the start number on 1d100 |
|
endRoll |
Number |
<optional> |
|
object |
Object | Element to add to the table, can be any type |
get() → {Object}
- Description:
Get an item from the table, based on percentages.
- Source:
Returns:
An item from the table
- Type
- Object
size() → {Number}
- Source:
Returns:
the number of items in the table.
- Type
- Number