variablesdynamicconnectionanylogicagent

How I link a variable in a sub-agent to a dynamic variable in another sub-agent in Anylogic


I have an Agent let's say "A" on the main agent, then I have another agent let's say "B" inside agent "A", and I created a dynamic variable in agent "A" and I want to use its measures results in a dynamic variable equation in agent "B", how can I do that?

I tried linking the agents via the connections, but it only sends messages, and I want the dynamic variable to read a value, not a message, then I tried to move the variables to the main agent and use the (main.variablename) in both agents "A & B" it gave a syntax error and refused to run the model

I tried chat GPT as well, but it wasn't so much of a help, YouTube, and Anylogic's help.


Solution

  • In B, you can access your parent agent A using a.myDynamicVariable

    Check for the small layer pointers AnyLogic creates for you, they look like this:enter image description here

    Also see https://anylogic.help/advanced/code/access.html#where-am-i-and-how-do-i-get-to