You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
--register a few scripts, then tell it to "go" and it will pick a random one based on the probability weights you specified. outcomes are mutually exclusive. To make independent random events, call the script multiple times.
Allows mutually-exclusive random events. Register a list of scripts along with positive integer relative weights, then tell the script to select one of them with the specified probabilities and run it.
The weights must be positive integers, but they do NOT have to sum to 100 or any other particular number.
The outcomes are mutually exclusive: only one will be triggered.
If you want multiple independent random events, call the script multiple times.
99% of the time, you won't need to worry about this, but just in case, you can specify a name of a list of outcomes to prevent interference from other scripts that call this one.
That also permits situations where you don't know until runtime what outcomes you want.
For example, you could make a reaction-trigger that registers the worker as a mayor candidate, then run this script to choose a random mayor from the list of units that did the mayor reaction.
arguments:
-help
print this help message
-outcomeListName name
specify the name of this list of outcomes to prevent interference if two scripts are registering outcomes at the same time
if none is specified, the default outcome list is selected automatically
-command [ commandStrs ]
specify the command to be run if this outcome is selected
must be specified unless the -trigger argument is given
-weight n
the relative probability weight of this outcome
n must be a non-negative integer
if not specified, n=1 is used by default
-trigger
selects a random script based on the specified outcomeList (or the default one if none is specified)
-preserveList
when combined with trigger, preserves the list of outcomes so you don't have to register them again
it is extremely highly recommended that you always specify the outcome list name when you give this command to prevent almost certain interference
if you want to trigger one of 5 outcomes three times, you might want this option even without -outcomeListName
most of the time, you won't want this
will NOT be preserved after the user saves/loads (ask expwnent if you want this: it's not that hard but if nobody wants it I won't bother)
performance will be slightly faster if you preserve the outcome lists when possible and trigger them multiple times instead of reregistering each time, but the effect should be small
-withProbability p
p is a real number between 0 and 1 inclusive
triggers the command immediately with this probability
-seed s
sets the random seed (guarantees the same sequence of random numbers will be produced internally)
use for debugging purposes
-listOutcomes
lists the currently registered list of outcomes of the outcomeList along with their probability weights