Simulation
Build live digital twins of your model — track real-world data over time, project scenarios into the future, and let agent behavior animate the graph.
Adding Charts, Sliders, and Checkboxes
IntermediateDrop charts, value tiles and controls onto a simulation diagram to turn it into an interactive dashboard your stakeholders can explore.
Reading Connected Agents in Rhai
IntermediateUse get_connected, sum_prop, and count_prop to let agents read each other's state through the graph — the way Metapad agents coordinate.
Adding Agents to a Scenario
BeginnerBring nodes to life as agents by dragging them from the Simulation Toolbox onto a simulation diagram. One node, many agents — the scaling pattern.
Simulation Diagrams
BeginnerA simulation diagram is a dashboard for a scenario or a whole twin: agents, links, charts and controls on one canvas, all computed live from your model.
Live Twins: A First Look
BeginnerWhat live twins are, when to use them, and how they sit on top of your existing model. Read this first before creating a twin or entering data.
Creating Twins and Scenarios
BeginnerSet up your first twin, give it a timeline, then add one or more scenarios to compare alternatives.
Writing Act Methods
AdvancedWhen property formulas aren't enough — write a Rhai script that runs once per agent per timestep and updates several properties together.
Writing Property Formulas
IntermediateCompute property values automatically with short Rhai expressions — spreadsheet formulas that know about your graph.
Diagnosing Simulation Errors and Warnings
IntermediateThe Scenario Diagnostics tab tells you whether a scenario is healthy — cycles, unresolved references, runtime warnings, authoring errors all in one place.
Entering Time Series Data
BeginnerUse the Time Series Grid in the agent properties panel to record values across timesteps — the spreadsheet inside your model.
Playing Through a Simulation Step by Step
IntermediateWalk a simulation forward one round at a time and make a decision in each round — like a board game. Works in the editor, in the Reader and on published sites.
Putting a Twin on a Calendar
IntermediateGive a twin a time unit and a start date, and its timesteps become real dates: weeks, months, quarters. Read results per month or year, follow today's date, and let viewers pick a time range — without changing a single computed value.
Mixing Live Data and Forecasts with the Time Slider
AdvancedAdd a time slider to a dashboard to mark where history ends and the forecast begins, and use forecast_from() in formulas to switch between actual figures and simulated values.
Bringing Live Data into a Twin
IntermediateConnect a twin to a live data source and fetch actual figures into a scenario, by hand or automatically whenever a dashboard is opened.
Building a Live Data Provider
AdvancedThe contract a web service implements to deliver actual figures into a Metapad twin: what Metapad requests, how periods are calculated, and what to answer.
Running a Multiplayer Game
IntermediateLet several people play one simulation together, each on their own device, with you as the facilitator.
__dtRhaibothThe scenario's step size — for example, 1.0 if start and end times are in months and dt is 1, or 1/12 if start and end are in years and you're stepping monthly. Use it to scale rates that are expressed per unit of natural time, so a formula stays correct even if the scenario's granularity changes later.
agent.has_propRhaibothCheck whether a property exists on the agent. Returns true if the property is defined on the agent's node type, false otherwise. Useful when working with optional properties or when writing formulas that adapt to different agent types in the same model.
count_propRhaibothCounts how many agents in an array have a specific value for a given property. Common pattern: counting connected agents in a particular state (e.g., active members of a team, completed steps of a process). The comparison is exact — string equality for text properties, numeric equality for numbers.
sum_propRhaibothSums a numeric property across an array of agents. Most often used in combination with getconnected to roll up values from connected agents — total payroll, total inventory, total revenue. Non-numeric or missing properties evaluate to 0, so a partially-filled set still produces a clean number.
__timestepRhaibothThe current timestep's index — 0 at the start of the scenario, 1 at the next step, and so on. Available as a scope variable inside every formula and act method. Useful for periodic logic ('once per year'), startup conditions, or any rule that depends on absolute time within the scenario.
agent.set_propRhaiact_methodWrite a value to one of the agent's properties at the current timestep. Only available inside an act method — property formulas don't use setprop, they return their result instead. setprop can override values that property formulas just computed for the same timestep, so use it when behavior touches multiple properties or depends on state-machine-like logic.
get_connectedRhaibothReturns the agents connected to the given agent via a relationship type. Walks the link in either direction, so the same call works whether your agent is the source or the target.
agent.get_propRhaibothRead a property's value on the current agent. The simplest form returns the value at the current timestep. Add a negative offset to look back in time — useful for self-referential formulas where the new value depends on the old one. The return type matches the property's data type: a number for Number properties, true/false for Boolean, a string for everything else.
forecast_fromRhaibothThe timestep index where the forecast starts, as set by the dashboard's time slider (Forecast from) — or () when there is no cutoff. Available in every formula and act method. Use it to show actual figures before the cutoff and simulated values from it on.
This content was written collaboratively with AI.