Exiting and Detaching

exit and detach Functions

The RACE JS SDK provides two functions for ending a player's participation in a Race game:

  • exit(): This function allows a player to exit the game gracefully. It sends an ExitGame instruction to the Transactor, which triggers the settlement process for that player. This means that the player's winnings or losses are calculated and distributed, and their stake is returned or forfeited according to the game rules. By default, the exit function also disconnects the client from the Transactor server.

  • detach(): This function simply disconnects the client from the Transactor server without initiating the exit process. This can be useful if the player wants to temporarily disconnect but intends to rejoin the game later.

Difference and Appropriate Usage

The key difference between exit and detach lies in their effect on the player's participation in the game:

  • Exiting: When a player exits, they are effectively leaving the game and cannot rejoin the same game session. Their assets are settled, and the game state is updated to reflect their departure. This is the appropriate action when a player wants to permanently leave the game and finalize their winnings or losses.

  • Detaching: When a player detaches, they are only disconnecting from the Transactor server but remain a participant in the game. Their stake remains in the game's stake account, and they can potentially rejoin the game later by reconnecting to the Transactor. This is useful for scenarios where a player may need to temporarily disconnect due to network issues or other reasons but intends to resume playing later.

Here's a summary of when to use each function:

  • Use exit() when the player wants to permanently leave the game and finalize their settlements.

  • Use detach() when the player wants to temporarily disconnect but intends to rejoin the game later.

It's important to note that the game rules may impose restrictions on when players can exit or rejoin a game. Developers should clearly communicate these rules to players through the game UI and ensure that the SDK functions are used appropriately within the game flow.

Last updated