♠️
RACE Protocol
NFT PresaleDiscord
  • ❤️Official Docs & Links
  • ⏳Progress Overview
  • RACE Protocol
    • 🏗️System Architecture
      • Components
      • On-chain Accounts
      • Synchronization
      • Randomization
      • Payment
    • 🎲Game Development
      • Game Handler
      • Effect
      • Event Handling
      • Race API
        • Arweave Integration
      • Race JS SDK
        • Installation and Setup
        • Key Components
          • AppClient
          • SubClient
          • Events
          • Game Context
          • Decryption Cache
        • Advanced Features
          • Getting Revealed Knowledge
          • Exiting and Detaching
          • Submitting Messages
          • Sub-game Interaction
        • Best Practices
        • API Reference
        • Troubleshooting
    • 🧪Testing
      • Race Test Kit
      • Unit Testing
      • Integration Testing
      • Additional Considerations
    • 🧱Modules & Features
      • Encryption Methods
      • Command-line Tools
      • Configuration Options
      • Blockchain Transport Implementations
    • 📃Smart Contract
      • Solana Program
    • 🔦Examples and Use Cases
      • Draw Card Game
      • Raffle Game
      • Other Examples
  • RACE Games
    • ♠️RACE Poker app
      • 🎮Start playing in minutes
        • 💰Cash and sit-n-go
        • 🏆Tournaments
      • 🎨Workshop
        • 🏆Create cash games
        • 🏨Create tourneys
      • 💡Concept introduction
      • 🏗️System architecture
      • 👾Game Flow
      • 🎲Cards shuffling
      • ☎️Communication
      • 🔐Key sharing/decryption
      • 💱Cash flow structure
    • ⚡Solfast
      • 🎲Game modes
  • RACE RESEARCH
    • 👾No-Code Development
      • Brainstorming
      • Implementation Approach
      • Project Status
    • 0️⃣Zero-Knowledge Proofs
      • Brainstorming
      • Integration steps
        • Verifiable Randomness Generation
        • Private Game State Updates
        • Verifiable Settlements
        • Private Player Actions
      • Project Status
    • 🛡️Security Audit Report
      • Executive summary
        • Introduction to Race Protocol
        • Audit Methodology
      • Findings
        • Smart Contract Security
        • WebAssembly Security
        • Client-side Security (Race SDK)
        • Server-side Security
        • Randomization and Encryption
        • On-chain Account Management
        • Synchronization Mechanisms
        • Payment Handling
      • Recommendations
      • Conclusion
  • RACE DAO
    • 😎About
    • 🫂Community
    • 🖼️NFT Collection [!]
Powered by GitBook
On this page
  • Processing Custom Events
  • Processing Built-in Events
  • Event Loop
  1. RACE Protocol
  2. Game Development

Event Handling

The game handler in Race Protocol is event-driven, meaning that it processes incoming events to update the game state and trigger corresponding actions. These events can be categorized into two main types:

  • Custom Events: These are game-specific events defined by the developer to represent player actions, decisions, and other occurrences within the game. Examples include placing a bet in a poker game or choosing rock, paper, or scissors in a Roshambo game.

  • Built-in Events: These are predefined events handled by the Race Protocol itself. They represent system-level actions and state changes, such as game initialization, player joins and exits, randomness generation, and settlements.

Processing Custom Events

When the game handler receives a custom event, it typically follows these steps:

  • Deserialization: The event data is deserialized from its binary format into the corresponding custom event struct defined by the developer.

  • Validation: The handler validates the event based on the current game state and rules. For example, it may check if the player sending the event is allowed to perform the action at the current stage of the game.

  • State Update: If the event is valid, the game handler updates the game state accordingly. This may involve changing player attributes, transitioning to a different game stage, or triggering other game-specific logic.

  • Effect Generation: Based on the updated game state and the nature of the event, the handler may generate effects using the Effectobject. These effects can trigger actions like revealing hidden information, assigning secrets, or initiating settlements.

Processing Built-in Events

Built-in events are handled by the Race Protocol itself, but the game handler may need to respond to them or perform specific actions based on the event type. Some examples include:

  • GameStart: When the game starts, the handler may need to initialize game-specific data structures, generate randomness, and assign initial states to players.

  • Join: When a new player joins, the handler may need to update player lists, adjust game state accordingly, and potentially trigger game start logic if enough players have joined.

  • RandomnessReady: When the randomness generation process is complete, the handler can access the revealed random values and use them within the game logic.

  • SecretsReady: When secrets are shared for revealing hidden information, the handler can decrypt the information and update the game state accordingly.

  • Settle: When a settlement transaction is confirmed on the blockchain, the handler may need to update player balances and potentially trigger game-end logic.

Event Loop

In a real-world scenario, the Transactor server runs an event loop that continuously processes incoming events. This loop reads events from both the client and any pending dispatched events (e.g., timeouts) and passes them to the game handler for processing. The handler then updates the game state and potentially generates new events or effects, which are handled by the event loop and broadcasted to participants.

This event-driven architecture ensures that the game progresses smoothly and that all participants have a consistent and synchronized view of the game state.

By understanding how to define custom events and respond to built-in events, developers can build complex and engaging game logic on top of Race Protocol, leveraging the benefits of blockchain technology and a secure, transparent runtime environment.

PreviousEffectNextRace API

Last updated 1 year ago

🎲