Core Event API
These functions are only available to classes that inherit from
Multisynq.Model or Multisynq.View.- publish()
- subscribe()
- unsubscribe()
- unsubscribeAll()
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
- Model Handlers
- View Handlers
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:- View → Model
- Model → View
- Model → Model
- View → View
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:- Global Scopes
- Model ID Scopes
- Custom Scopes
Built-in scopes available everywhere
Practical Examples
🎮 Game Input System
🎮 Game Input System
Complete input handling pattern
🎨 Visual Effects System
🎨 Visual Effects System
Model-triggered visual effects
🤖 AI Agent Communication
🤖 AI Agent Communication
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
- State Updates
- Lifecycle Events
- Timer Events
Centralized state management
Event Debugging
- Event Logging
- Event Validation
Track event flow in development
Performance Considerations
- Throttling
- Batching
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.