Effect

The Effectobject plays a crucial role in Race Protocol by acting as a bridge between the game handler (WASM) and the runtime environment (Transactor or client). It serves two primary purposes:

  • Providing Context Information: The Effect object provides the game handler with relevant context information about the game and its environment. This information includes:

    • Event Timestamp: The timestamp of the event being handled, ensuring consistent timing across all nodes.

    • Number of Players and Servers: The total number of players and servers involved in the game, including those with pending status. This information can be used to determine if there are enough participants to start the game or trigger specific game logic.

    • Revealed Hidden Knowledge: This includes any previously hidden information that has been revealed to all participants, such as the outcome of randomization processes or player decisions.

  • Enabling Runtime Interaction: The Effect object allows the game handler to trigger actions and interact with the runtime environment. This includes:

    • Initializing Randomness: The game handler can use the Effect object to request the creation of randomness with specific characteristics (e.g., shuffled list, lottery). The Transactor and validator servers then handle the actual randomization process and share the necessary secrets with the game handler through the Effect object.

    • Assigning and Revealing Secrets: The game handler can use the Effect object to assign secrets to specific players, allowing them to decrypt and access hidden information relevant to their gameplay. It can also reveal secrets publicly to make information visible to all participants.

    • Triggering Settlements: When the game concludes, the game handler can use the Effect object to specify how assets should be distributed among players. This triggers the Transactor to create and submit a settlement transaction to the blockchain.

    • Managing Timeouts: The game handler can use the Effect object to set timeouts for player actions or general waiting periods. This helps ensure that the game progresses smoothly and prevents stalling.

    • Launching Sub-games: In games that require nested game structures, the game handler can use the Effect object to launch sub-games with specific configurations and initial states.

    • Emitting Bridge Events: The game handler can use the Effect object to send custom events to sub-games or other connected components, enabling communication and coordination between different parts of the game.

By utilizing the Effect object, the game handler can access essential context information and trigger actions within the runtime environment without directly interacting with the blockchain or other components. This promotes modularity, simplifies testing, and ensures that the game logic remains pure and deterministic.

The next section will discuss event handling in detail and explain how the game handler processes different types of events to drive the game forward.

Last updated