Reference 〉Function

Helipad.addBreedParam( str name, str title, str type, str|bool|num|dict dflt, dict opts = {}, str prim = None, bool runtime = True, func callback = None, str desc = None )

Adds a parameter to the control panel that takes a separate value for each registered breed. The current value of the parameter for any or all breeds can be retrieved by passing an appropriate parameter identification tuple to model.param().

Parameters

  • name str, required

    A slug-type string to be used to refer back to the parameter in other functions.

  • title str, required

    The title of the parameter, to be displayed in the GUI.

  • type str, required

    What type of control to display. Possible values are 'menu', 'check', 'slider', 'checkentry', or 'hidden'. (Note that per-breed checkgrids are not supported)

  • dflt str|bool|num|dict, required

    The default value of the parameter. A menu should have a string here, a check a boolean, a slider a number, and a checkentry a bool, int, or string. Can also take a dict, with keys corresponding to the different breeds, in order to set a different default value for each breed.

  • opts dict, optional

    Options for the parameter type.

    • A slider should have a dict with keys 'low', 'high', and 'step', with numeric values, corresponding to the max and min values and the slider's increment. Alternatively opts can take a list of integers for a slider that slides over defined values.
    • A menu should have key-value pairs corresponding to menu items, with the key the value returned by the parameter, and the value the label displayed in the GUI.
    • Checks, checkentries, or hidden parameters do not need an opts parameter.

    Default value: {}

  • prim str, optional

    Which agent primitive's breeds the parameter should apply to. This parameter is optional IF there is only one agent primitive, otherwise it is required.

    Default value: None

  • runtime bool, optional

    Whether the parameter can be changed during the model's runtime. If set to False, the parameter will be disabled while the model is running.

    Default value: True

  • callback func, optional

    An optional function that will execute when the parameter changes. The function takes four arguments: model, the model object; var, the name of the parameter (the first argument of model.addBreedParam); breed, the name of the breed whose parameter was changed; and val, the new value of the parameter.

    Default value: None

  • desc str, optional

    A long description to display as a tooltip. Note that tooltips require PMW when using the Tkinter frontend.

    Default value: None

Notes and Examples

  1. charwick

    Mar 23, 2020 at 1:06

    This example creates three breed parameters: a slider, a check, and a menu, each of which will take a separate value for each breed of the specified primitive. In this case there are two breeds, so we have two values for each parameter.

    heli.addBreed('hobbit', 'D73229', prim='agent')
    heli.addBreed('dwarf', '2D8DBE', prim='agent')
    
    heli.addBreedParam('rbd', 'Demand for Real Balances', 'slider', dflt={'hobbit':7, 'dwarf': 35}, opts={'low':1, 'high': 50, 'step': 1}, prim='agent', callback=rbalUpdater)
    heli.addBreedParam('active', 'Active?', 'check', dflt=True, prim='agent')
    heli.addBreedParam('mode', 'Mode of Interaction', 'menu', opts={
    	'a': 'Aggressive',
    	'c': 'Cooperative',
    	's': 'Spiteful'
    }, dflt='a', prim='agent')

    This will display in the control panel like this. Note the separate defaults on the slider parameter, as we passed a dict for the dflt parameter rather than a number.

  2. Contribute a Note

    Your email address will not be published. Required fields are marked *

    You may use limited HTML for formatting. Please embed blocks of code in <pre><code> </code></pre> tags.