Modding:weighttable
From DoomRL Wiki
Revision as of 17:13, 11 June 2013 by Shark20061 (Talk | contribs)
Weight tables are objects that choose an object from a list at random, using the provided weights as the relative probably for each choice.
Weight Table API
- weight_table.new() → weight_table
Creates a new, empty weight table.
- Returns: A reference to an empty weight table.
- add(<any> object, integer [weight])
Adds an item to the weighttable.
- object: The thing to add.
- weight: Optional. The weight to use for this object. If omitted, the object's own weight property will be used, or 1 is used if the object doesn't have a weight property.
- size()
Gets the number of elements in this weight table.
- Returns: The number of elements in the table.
- roll()
Picks an object at random from the table using the indicated weights.
- Returns: An object rolled at random.
Weight Table Object
Properties | ||
_elements | table | The list of elements in the weight table. |
_weights | table | The weights of each corresponding element. |
_weight | integer | The total weight of all elements in the table. |