Skip to content

$this->bga->tournament

Access the tournament associated with the current table and persist player data during that tournament.

API

isTournament(): bool

Return whether the table is a tournament encounter.

getInfo(): array

Return tournament information, or an empty array outside a tournament. Available fields can include id, name, championship_name, oot_options, tournament_group, tournament_parent_id, and avatar.

getSeedInfo(): array

Return tournament seeds, or an empty array outside a tournament. Fields can include tournament_seed, step_seed, and parent_tournament_seed, for game logic that needs deterministic randomness.

storePlayerGameData(int $playerId, string $key, mixed $data): void

Store JSON data for a player in the current tournament. The cumulative limit is 64 KiB per player and tournament.

retrievePlayerGameData(int $playerId, string $key): mixed

Read a value, returning null if absent. Include % in the key to retrieve a map of matching keys to decoded values. If no keys match, return an empty array.

removePlayerGameData(int $playerId, string $key): void

Remove a player’s value. Use % in the key to remove matching entries. Tournament data is also removed when the tournament finishes.

Example

if ($this->bga->tournament->isTournament()) {
    $info = $this->bga->tournament->getInfo();
    $seeds = $this->bga->tournament->getSeedInfo();
}

Scope and validation

Guard player-data reads, writes, and removals with isTournament(): they fail for a table outside a tournament. getInfo and getSeedInfo already return an empty array without contacting the main site in that case.

Stored keys must contain 1–16 ASCII letters or digits. Retrieval and removal patterns may additionally contain %. Player IDs must be positive. The total JSON data across all keys for a player and tournament must fit within 65,535 bytes.

Data belongs to the current tournament ID. Stages with different tournament IDs have separate data even when they share a parent tournament. Use this API for tournament rules, such as retaining a deck choice between encounters. Use legacy for campaign progress that must survive after the tournament.

Tournament information fields

Field Meaning
id Tournament ID.
name Tournament name.
championship_name Championship name, when applicable.
oot_options Out-of-time policy, such as no_kick or auto_kick.
tournament_group Associated BGA group ID.
tournament_parent_id Parent tournament ID, when applicable.
avatar Tournament avatar reference.

Seed scopes

Seed Shared by
tournament_seed All encounters in the tournament.
step_seed All encounters in one tournament step.
parent_tournament_seed Encounters associated with the same parent tournament, when available.

A shared seed can support an identical generated setup across encounters in a step. The API returns the seed; it does not seed your game's random generator automatically. Tournament information and seeds are cached within the request.

Player-data example

if ($this->bga->tournament->isTournament()) {
    $savedDeck = $this->bga->tournament->retrievePlayerGameData($playerId, 'deck');
    if ($savedDeck === null) {
        $this->bga->tournament->storePlayerGameData($playerId, 'deck', $chosenDeck);
    }

    // Read or remove a group of keys with a shared prefix:
    $roundData = $this->bga->tournament->retrievePlayerGameData($playerId, 'round%');
    $this->bga->tournament->removePlayerGameData($playerId, 'round%');
}