Skip to content

Module: tournament

Table of contents

Functions

Functions

createAsync

createAsync(payload): Promise<Tournament>

Opens the tournament creation dialog if the player is not currently in a tournament session.

Example

// Create a tournament for a specific level.
const payload = {
    initialScore: 100,
    config: {
        title: "Level 1 Tournament",
    },
    data: {
        level: 1,
    },
};

Wortal.tournament.createAsync(payload)
 .then(tournament => console.log(tournament.payload["level"]));

Parameters

Name Type Description
payload CreateTournamentPayload Payload that defines the tournament configuration.

Returns

Promise<Tournament>

Promise that resolves with the created tournament.

Throws

  • INVALID_PARAM
  • INVALID_OPERATION
  • NETWORK_FAILURE
  • DUPLICATE_POST
  • NOT_SUPPORTED

getAllAsync

getAllAsync(): Promise<Tournament[]>

Returns a list of eligible tournaments that can be surfaced in-game, including tournaments:

  • The player has created
  • The player is participating in
  • The player's friends (who granted permission) are participating in

The tournaments returned are active. A tournament is expired if its end time is in the past. For each tournament, there is only one unique context ID linked to it, and that ID doesn't change.

Example

Wortal.tournament.getAllAsync()
 .then(tournaments => console.log(tournaments.length));

Returns

Promise<Tournament[]>

Promise that resolves with an array of active tournaments.

Throws

  • NETWORK_FAILURE
  • INVALID_OPERATION
  • NOT_SUPPORTED

getCurrentAsync

getCurrentAsync(): Promise<Tournament>

Fetch the tournament out of the current context the user is playing. This will reject if there is no tournament linked to the current context. The tournament returned can be either active or expired (A tournament is expired if its end time is in the past). For each tournament, there is only one unique context ID linked to it, and that ID doesn't change.

Example

Wortal.tournament.getCurrentAsync()
.then(tournament => {
    console.log(tournament.id);
    console.log(tournament.endTime);
});

Returns

Promise<Tournament>

Promise that resolves with the current tournament. Rejects if there is no tournament linked to the current context.

Throws

  • PENDING_REQUEST
  • NETWORK_FAILURE
  • INVALID_OPERATION
  • TOURNAMENT_NOT_FOUND
  • NOT_SUPPORTED

joinAsync

joinAsync(tournamentID): Promise<void>

Request a switch into a specific tournament context. If the player is not a participant of the tournament, or there are not any connected players participating in the tournament, this will reject. Otherwise, the promise will resolve when the game has switched into the specified context.

Example

Wortal.tournament.joinAsync("1234567890")
 .then(() => console.log("Switched into tournament!"));

Parameters

Name Type Description
tournamentID string ID of the desired tournament context to switch into.

Returns

Promise<void>

Promise that resolves when the game has switched into the specified tournament context, or rejects otherwise.

Throws

  • INVALID_PARAM
  • INVALID_OPERATION
  • TOURNAMENT_NOT_FOUND
  • SAME_CONTEXT
  • NETWORK_FAILURE
  • USER_INPUT
  • NOT_SUPPORTED

postScoreAsync

postScoreAsync(score): Promise<void>

Posts a player's score. This API should only be called within a tournament context at the end of an activity (example: when the player doesn't have "lives" to continue the game). This API will be rate-limited when called too frequently. Scores posted using this API should be consistent and comparable across game sessions. For example, if Player A achieves 200 points in a session, and Player B achieves 320 points in a session, those two scores should be generated from activities where the scores are fair to be compared and ranked against each other.

Example

Wortal.tournament.postScoreAsync(200)
 .then(() => console.log("Score posted!"));

Parameters

Name Type Description
score number An integer value representing the player's score at the end of an activity.

Returns

Promise<void>

Promise that resolves when the score is posted.

Throws

  • INVALID_PARAM
  • TOURNAMENT_NOT_FOUND
  • NETWORK_FAILURE
  • NOT_SUPPORTED

shareAsync

shareAsync(payload): Promise<void>

Opens the share tournament dialog if the player is currently in a tournament session.

Example

Wortal.tournament.shareAsync({
  score: 3,
  data: { myReplayData: '...' }
});

Parameters

Name Type Description
payload ShareTournamentPayload Specifies share content.

Returns

Promise<void>

Promise that resolves if the tournament is shared, or rejects otherwise.

Throws

  • INVALID_OPERATION
  • TOURNAMENT_NOT_FOUND
  • NETWORK_FAILURE
  • NOT_SUPPORTED