Skip to content

Class "WeightedOutcomePicker"⚓︎

An example mod using the WeightedOutcomePicker class can be found here.

Info

This class can be obtained using its constructor:

Example Code
1
local wop = WeightedOutcomePicker()

Constructors⚓︎

WeightedOutcomePicker ()⚓︎

WeightedOutcomePicker WeightedOutcomePicker ( )⚓︎


Functions⚓︎

AddOutcomeFloat ()⚓︎

void AddOutcomeFloat ( int Value, float Weight, int ScaleFactor = 100 )⚓︎

picker:AddOutcomeFloat(3, 0.2) -- ~9% Adds an outcome to the outcome selector with the specified Weight. The internal weight is still an integer calculated like this: fWeight * scaleFactor, where ScaleFactor is the maximum weight (equivalent to 1.0). picker:AddOutcomeFloat(2, 1.0) -- ~45% local picker = WeightedOutcomePicker()

1
???+ example "Example Code"
picker:AddOutcomeFloat(1, 1.0) -- ~45%

AddOutcomeWeight ()⚓︎

void AddOutcomeWeight ( int Value, int Weight )⚓︎

picker:AddOutcomeWeight(3, 5) -- 5% picker:AddOutcomeWeight(1, 65) -- 65% local picker = WeightedOutcomePicker()

1
2
3
picker:AddOutcomeWeight(2, 30) -- 30%
Adds an outcome to the outcome selector with the specified `Weight`.
???+ example "Example Code"

ClearOutcomes ()⚓︎

void ClearOutcomes ( )⚓︎

Clears all outcomes from the outcome picker.

GetNumOutcomes ()⚓︎

int GetNumOutcomes ( )⚓︎

Returns the number of outcomes in the outcome picker.

GetOutcomes ()⚓︎

table[] GetOutcomes ( )⚓︎

Returns a table containing a list of all outcomes in the outcome picker. print(outcome.Value, outcome.Weight) end

1
2
3
4
5
* Weight: weight of the outcome
- The returned table contains a list of outcomes, where each outcome is a table containing the following fields:
* Value: value of the outcome
???- info "Table structure & usage"
for i, outcome in ipairs(p:GetOutcomes()) do

PickOutcome ()⚓︎

int PickOutcome ( RNG RNG )⚓︎

Returns a random outcome from the list in WeightedOutcomePicker. Accepts RNG.

RemoveOutcome ()⚓︎

void RemoveOutcome ( int Value )⚓︎

Removes an outcome from the outcome picker with the given Value.