Open up the init.json
file. It should look like:
[
{
behaviors: [
"@hash/create-scatters/create_scatters.js",
"create_people.js",
"@hash/create-agents/create_agents.js",
"@hash/remove-self/remove_self.js",
],
scatter_templates: [
{
template_name: "homes",
template_count: 100,
height: 2,
color: "yellow",
},
{
template_name: "groceries",
template_count: 3,
height: 2,
color: "purple",
},
{
template_name: "offices",
template_count: 10,
height: 2,
color: "grey",
},
],
people_template: {
behaviors: ["infection.js", "check_infected.js", "daily_movement.js"],
severity: "moderate",
out: false,
social_distancing: false,
},
},
];
init.json
defines the 'initial state' of the simulation. In this case we're using some 'creator' utility behaviors, attached to a setup agent, who plays no role in our experiments beyond helping get our world set up correctly.
See Initializing Agents for more on init.json and creator agents.
This setup agent has four behaviors attached to it which will help populate our world. In order:
@hash/create-scatters/create_scatters.js
. This is a shared behavior (hIndex) that, when added to an agent, will create all of the associated scatter_templates
. It's called scatter because it's scattering the child agents around the map.create_people
, a behavior local to this simulation. In this behavior we've defined our people agents and associated them with their homes, offices, and groceries.@hash/create-agents/create_agents.js
- another shared behavior (hIndex). In our previous two functions we didn't fully create our agents, we just added them to an agents object on the "creator agent". This third behavior iterates through that object and sends messages to the reserved hash keyword create_agent to instantiate all of our new agents.@hash/remove-self/remove_self.js
, which will appropriately enough remove itself from the simulation. We don't want to constantly be generating new grocery stores, which is what we'd end up with here otherwise!This kind of 'creator agent' pattern is a common and recommended method for generating lots of agents. It’s worth double-checking to make sure fully understand what's going on in this step.
Now that we understand how to instantiate our agents, let’s create a hospital. Since we’re not dynamically generating multiple hospitals, we could just add the hospital directly in our init.json
initial state page.
{
"agent_name": "Hospital",
"position": [0, 0],
"height": 4,
"color": "blue",
"behaviors": [],
"type": "hospital"
}
Or, we can follow the creator pattern and add it as a "stack" (as it's at a specific location). To do that we'd add stack_templates
to our agent, as well as add the @hash/create-stacks/create_stacks.js
behavior. Since it's a shared behavior, you can search in the index panel in the lower left for it. Double click and it will be added to your simulation.
[
{
behaviors: [
"@hash/create-scatters/create_scatters.js",
"@hash/create-stacks/create_stacks.js",
"create_people.js",
"@hash/create-agents/create_agents.js",
"@hash/remove-self/remove_self.js",
],
// ...
stack_templates: [
{
template_name: "hospitals",
template_count: 1,
template_position: "center",
agent_name: "Hospital",
behaviors: [],
height: 4,
color: "blue",
},
],
},
];
You can set the position, color, and height as whatever you’d like.
Click Reset Simulation in the bottom right under the 3D viewer. If you added the hospital directly to init.json
you should see it appear in the viewer - if you're using create_stacks
then click Start Simulation. After three frames you should see it. Congratulations, you’ve built your first hospital! We’re proud of you.
At the moment the hospital doesn’t do anything. It just sits there, begging for a purpose. So let's add some functionality. There’s two things we want our hospital to do.
Previous
Next