♠️
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
  • Sub-games and the Role of SubClient
  • Creating and Using SubClient
  1. RACE Protocol
  2. Game Development
  3. Race JS SDK
  4. Key Components

SubClient

Sub-games and the Role of SubClient

In some games, it may be necessary to create nested game structures, where a main game spawns sub-games with their own independent state and logic. Race Protocol supports this concept through sub-games. A sub-game is essentially a child game that is launched and managed by the main game. It has its own game handler, state, and event stream, but it is still connected to the main game and can communicate with it through events.

The SubClient class in the RACE JS SDK provides the interface for interacting with sub-games on the client side. It is similar to the AppClient in terms of functionalities, but it specifically focuses on managing the interaction between the client and a particular sub-game.

Creating and Using SubClient

To create a SubClient instance, you first need an initialized AppClient instance. You can then use the subClient function of the AppClient, providing the following information:

  • subId: The unique identifier of the sub-game you want to connect to.

  • onEvent: A callback function that will be invoked whenever an event occurs within the sub-game.

Here's an example of creating and using a SubClient:

// Assuming appClient is an initialized AppClient instance

const subId = 1; // Replace with your sub-game ID

const subClient = await appClient.subClient({
  subId,
  onEvent: (context, state, event) => {
    // Handle sub-game events here
  },
});

// Now you can use subClient to interact with the sub-game, 
// submit events, and access its state information.

Once you have a SubClient instance, you can use its functions to:

  • Connect to the sub-game: The attachGame function connects the client to the sub-game's event stream.

  • Submit events: The submitEvent function allows players to submit custom events to the sub-game.

  • Handle events: The SubClient provides event listeners that can be used to react to incoming events and update the sub-game UI.

  • Access game context and state: The SubClient provides access to the sub-game's GameContext and handler state.

By utilizing the SubClient, developers can build client-side applications that interact with both the main game and its sub-games, enabling complex and engaging gameplay experiences within the Race Protocol framework.

PreviousAppClientNextEvents

Last updated 1 year ago

🎲