Sets or gets a parameter. Note the parameter must have been previously registered with Params.add()
.
Parameters
param — str|tuple, required
A parameter identification string or tuple. A string value indicates a global parameter. Per-good parameters can be indicated with a three-item tuple,
('paramName', 'good', 'goodName')
. A per-breed parameter can be indicated with a three- or four-item tuple,('paramName', 'breed', 'breedName', 'primitive')
, with the last element optional if there is only one primitive.
If only this argument is set, the function returns the value of the named parameter.
Parameter values for all goods or breeds can be retrieved, but not set, with a two-item tuple (e.g.('name', 'good')
). This will return adict
of all item values for the parameter ifval
is not set, but will throw an exception ifval
is set.val — str|bool|num|list[str], optional
If this argument is set, the function sets the value of the parameter to
val
. The data type must be appropriate to the parameter type: a slider takes a number, a menu takes a string, a checkbox takes a bool, a checkentry takes a bool, a string, or an int, depending on the type, and a checkgrid takes a list of strings.Default value: None
Return Value — str|bool|num|dict|None
If val
is not set, returns the parameter value: a string if the parameter is a menu, a boolean if a checkbox, a number if a slider, a bool, int, or string if a checkentry, or a list of strings if a checkgrid. If a two-item tuple is passed for param
without specifying an item, the function returns a dict
with parameter values for all relevant items. If val
is set, the function sets the parameter to val
and does not return a value.
charwick
Mar 24, 2020 at 3:33This example doubles the value of the
'agentSpeed'
parameter.charwick
Jun 25, 2020 at 19:47A few examples to show the uses of the parameter identification pattern. Note that the fourth element of the breed parameter tuple can be omitted if there are not multiple agent primitives.
If there are multiple primitives so that the fourth tuple element is required, a dict of values for all breeds can still be gotten by passing
None
as the third tuple element.