Skip to main content

Two bodies

This example runs two bodies in one Space. A cart-pole and a light. The brain alternates between them. The cart-pole emits a CRITICAL event that the light receives directly via a lateral link.

The whole file

two-bodies.js:

Run

Real output

Two things to notice:
  1. The [light] alarm from cartpole lines come from the lateral link. The cartpole emits pole_critical; Plexa routes it directly to light.onPeerEvent. The brain is not involved. There is no broadcast: a third body would not have received it.
  2. light.toggle calls come from the brain, not the link. Both kinds of dispatch coexist.

What this proves

  • One Plexa Space can hold many bodies.
  • The brain can address either body by name.
  • Bodies can talk to each other directly with zero latency.
  • The brain never sees onPeerEvent calls; they are body-local concerns.

What does not work yet

  • There is no shared CRDT between bodies. If the light needs to know the cartpole’s exact angle, it has to be told via a peer event (or pull from the world state on the next brain tick).
  • Lateral events do not survive a process restart; only the brain’s memory does (via VerticalMemory).