Reputation: 99
I have a custom block that needs parameter and variable info from the agent passing through it. I would like to design this block for use with different agent types. How do I create a pulldown of all of the available agent types in the current model like in other built-in blocks? I'm assuming it's a parameter with an internal value, but just not sure of the parameter type, method to pull the agent types, etc. See picture below:
Upvotes: 0
Views: 350
Reputation: 2517
You use generic parameters (for the agent type that your custom block is defined within) as outlined in this help section: AnyLogic Help > Parameters, Variables, Collections > Parameters > Generic Parameters.
By giving the parametrized type a label of "Agent type:" (instead of the default "Generic parameter:") you can also make it look more as it does in AnyLogic's blocks.
(The main difference is that it's not in an Advanced properties section.)
Just remember to use whatever you named your generic type (e.g., T
) as the agent type for the blocks (or other code) inside your custom block (for those areas where you need to see it as that type instead of a generic Agent).
This is using Java generics under the covers, hence why there is some specific Java syntax such as T extends Agent
for the type parameter detail (which just means that the generic type T is some subclass (sub-type) of Agent).
Upvotes: 1
Reputation: 12793
You use type-casting as below. Note that the "Agent type" setting should stay at the default (and most generic) "Agent"
Upvotes: 1