Skip to main content
Events are the primary communication mechanism in Multisynq applications. The publish-subscribe (pub-sub) pattern enables clean, decoupled communication between Models and Views while maintaining perfect synchronization.

Core Event API

These functions are only available to classes that inherit from Multisynq.Model or Multisynq.View.
Sends an event to all subscribers
  • scope: Namespace for the event (String)
  • event: Name of the event (String)
  • data: Optional data payload (any serializable type)

Handler Requirements

Critical difference: Model and View handlers have different requirements!
Must use method names, not function expressions
This is because functions cannot be serialized, so only the method name is stored.

Event Routing Patterns

Understanding event routing is crucial for proper Multisynq development:
Events are transmitted to the synchronizer and mirrored to all users
Use case: User input, game actions, any synchronized state changes

Scopes and Namespacing

Scopes provide namespacing to avoid event name conflicts and enable targeted communication:
Built-in scopes available everywhere

Practical Examples

Complete input handling pattern
Model-triggered visual effects
Agent-specific communication channels

Best Practices

🎯 Targeted Communication

Use specific scopes for efficient communication

📦 Small Payloads

Keep event data small and simple

🔄 Avoid Chains

Don’t create Model → View → Model chains

🧹 Clean Up

Unsubscribe when no longer needed

Common Patterns

Centralized state management

Event Debugging

Track event flow in development

Performance Considerations

Avoid these performance pitfalls:
  1. High-frequency events: Don’t publish events every frame
  2. Large payloads: Keep event data minimal
  3. Circular subscriptions: Avoid event loops
  4. Unused subscriptions: Always clean up when done
Limit event frequency

Next Steps

Writing a Multisynq Model

Learn how to build robust, event-driven models

Writing a Multisynq View

Master view development and user interaction

Snapshots

Understand state persistence and recovery

Sim Time & Future

Master time-based behaviors and scheduling
Events are the nervous system of Multisynq applications. Understanding when and how to use them effectively is crucial for building responsive, maintainable multiplayer experiences.