♠️
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
  • GameContext Object and Client-side State
  • Information in GameContext
  • Accessing and Using GameContext
  1. RACE Protocol
  2. Game Development
  3. Race JS SDK
  4. Key Components

Game Context

GameContext Object and Client-side State

The GameContext object in the RACE JS SDK represents the current state of the game on the client side. It acts as a snapshot of the game's progress and contains various information necessary for the client application to display the game state and allow players to interact with it.

Information in GameContext

The GameContext object holds the following information:

  • gameAddr: The address of the Race game on the blockchain.

  • accessVersion: The access version of the game, which tracks the order in which players and servers joined.

  • settleVersion: The settle version of the game, which tracks the number of settlements that have occurred.

  • status: The current status of the game (e.g., "idle", "running", "closed").

  • nodes: A list of nodes (players and servers) participating in the game, along with their addresses, IDs, and connection status.

  • dispatch: Information about any pending dispatched events, such as timeouts.

  • handlerState: The current state of the game handler, managed by the WASM game bundle.

  • timestamp: The timestamp of the latest event processed by the game handler.

  • allowExit: A boolean flag indicating whether players are allowed to exit the game.

  • randomStates: A list of RandomState objects, each representing a randomness generation process and its current status.

  • decisionStates: A list of DecisionState objects, each representing a hidden decision made by a player and its current status.

  • checkpoint: An optional byte array containing the latest game state snapshot.

  • subGames: A list of SubGame objects representing any launched sub-games.

  • nextSettleVersion: The next settle version that will be used for the next settlement transaction.

  • initData: An optional byte array containing the initial game data.

  • maxPlayers: The maximum number of players allowed in the game.

  • players: A list of GamePlayer objects representing the players currently in the game.

  • entryType: The entry type of the game, which defines how players can join.

Accessing and Using GameContext

The AppClient and SubClient instances provide access to the GameContext object through their gameContext property. You can use this property to retrieve information about the game state and display it in the game UI.

Here's an example of accessing and using the GameContext:

// Assuming client is an initialized AppClient or SubClient instance

const gameContext = client.gameContext;

const currentStage = gameContext.stage;
const players = gameContext.players;

// Update the UI based on the current stage and player information

This code snippet demonstrates how the GameContext object provides valuable information about the game state, allowing the client application to display relevant information to the players and facilitate their interaction with the game.

PreviousEventsNextDecryption Cache

Last updated 1 year ago

🎲