Getting Revealed Knowledge

Using the getRevealed Function

In games with hidden information, the game handler may reveal certain elements of the game state to players at specific points in the game. This is typically done by sharing secret keys that allow players to decrypt the hidden information.

The RACE JS SDK provides the getRevealed function in both the AppClient and SubClient classes to access this revealed knowledge. The function takes the randomness ID as an argument. This ID is associated with the randomness generation process used to create the hidden information. The function then returns a map containing the decrypted values associated with that randomness.

Code Examples for Utilizing Revealed Information

Here's an example of using the getRevealed function to access and display revealed information in the game UI:

// Assuming client is an initialized AppClient or SubClient instance

const randomId = 1; // Replace with your randomness ID

const revealed = await client.getRevealed(randomId);

// Iterate over the revealed values and update the UI accordingly
for (const [index, value] of revealed) {
  // Example: Displaying revealed cards in a card game
  if (index === 0) {
    const playerCardElement = document.getElementById('playerCard');
    playerCardElement.innerHTML = value; // Display the card value
  }
}

This code snippet demonstrates how the getRevealed function can be used to retrieve decrypted information and update the game UI to reflect the revealed knowledge. The specific way you utilize the revealed information will depend on the nature of your game and its mechanics.

By using the getRevealed function, developers can ensure that players have access to the complete game state when necessary and can make informed decisions based on the revealed information.

Last updated