Reference 〉 Function

Helipad.agent( str|int var, str primitive = None )

Returns either a single agent object by ID, or a subset of agents by breed. To return all agents, use model.allagents.

Parameters

  • var str|int, required

    If var is a breed name, the function returns a list of all agents of that breed. If var is an int, the function returns the agent with that id.

  • primitive str, optional

    If var is a breed name, primitive specifies which primitive's breed to return. A value of None will select the first primitive in order, usually 'agent' unless that primitive has been removed or reordered.

    Default value: None

Return Value Agent|list[Agent]

An Agent object with agent.id==var if var is an int (or None if no agent matched the ID); otherwise a list of Agent objects with agent.breed==var.

Notes and Examples

  1. charwick

    Mar 24, 2020 at 3:24

    A few examples:

    a = model.agent('hobbit') #A list of all agents with breed 'hobbit'
    b = model.agent('retail', 'store') #returns a list of all store-primitive agents with breed 'retail'
    c = model.agent(32) #returns the agent whose id==32, regardless of the primitive

    If you want agents of all breeds of a particular primitive, you can access the model.agents property directly. If you want all agents of all primitives, use model.allagents.

    d = model.agents['store'] #A list of all agents with the 'store' primitive
    e = model.allagents #a flat dict with all agents of all primitives, keyed by agent ID
  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.

History