Figure out which step are we in the simulation

Hello,
How can an agent tell which step we are in the simulation? Say a behavior changes color of agent in 10 steps from now, how can the agent tell which step the simulation is?

ie how to return the simulation step

Is there a unique identifier for an agent that is always created and can be accessed?

Thanks

Hello,

Agents can individually track the simulation step by using the age.rs published behavior. You can add it to your simulation by using the lower left sidebar, and then add it to your agents’ behavior array like so:

{
  "behaviors": ["@hash/age.rs"],
  ...
}

You can then access the age field of the agent using state.get("age").

Regarding your second question, yes! Each agent is generated with a field called “agent_id” which is guaranteed to be unique uuid string. You can access it using state.get("agent_id").

Let me know if there’s anything else I can clarify for you.
-Nur

Thank you Nur,
Tried let age = the state.get(“age”) and then I console log it, I get null (?) on the developer’s console i opened.
it is under: https://core.hash.ai/@abenari/create-scatters0/main
in move_around.js , what am I doing wrong.?

I am successful at getting the agent ids , thanks again

Alon

ok, got it to work.

Only after I added it the “age.rs” in the init,json under behavor but not when I added it to the behavior of the specific agent.
What is the difference between the two locations I added the “age.rs”

That’s a good question. The distinction is between the ‘creator’ agent and the agents that are moving around in your simulation. This page of the docs explains how creator agents work, existing only for the first step of the simulation in order to generate the rest of the agents.

When you added the behavior under the creator agent:

{
    "name": "creator",
    "behaviors": [
     "@hash/age.rs",
      "create_scatters.js",
      "color_change.js",
      "create_agents.js",
      "@hash/remove-self/remove_self.js"
    ]
    ...
}

the behavior was not added to the actual agents you see later on in the simulation (since the creator agent is removed after the first step). When you added it to the behavior array under “scatter_templates” this made sure that the generated agents had the age behavior added to them:

"scatter_templates": [
      
      
      {
        "template_name": "horses",
        "template_count": 4,
        "behaviors": ["color_change.js","move_around.js","@hash/age.rs"],
      
        "height": 2,
        "random_movement_step_size": 3
      }