API Reference › Annotations › @ToClients
annotation

@ToClients

@ToClients event Name { … }

@ToClients marks an event as a directional remote event that travels from the authority down to clients — a broadcast, again the ordinary event bus with a direction flag. When the server emits it, the POD payload is serialized as an event id plus its packed fields and sent through the transport seam to the clients; each client's pump re-emits it into normal @On dispatch, so an @On(Name) handler on every client reacts. Use it for authoritative notifications a client should present but not decide — an explosion happened, a round ended, a pickup was granted. Its mirror is @ToServer, which carries client requests the other way.

Example

program ExplosionBroadcast {
  property EffectLog { count: int = 0 }
  model Client { EffectLog }

  @ToClients event Boom { column: int = 0, row: int = 0 }   # server -> clients broadcast

  @On(Boom) handler PlayExplosion {                  # every client reacts
    for (EffectLog) in query [EffectLog, {Client}] {
      EffectLog.count = EffectLog.count + 1
    }
  }

  entry {
    spawn Client { EffectLog { count: 0 } }
    emit Boom(column: 8, row: 3)                      # serialized to clients, re-emitted on arrival
  }
}
← All symbols