$this->bga->legacy
Store data that belongs to a game across multiple tables, such as campaign progress. Ordinary table data belongs in globals or your game database.
Player data
get(string $key, int $playerId, mixed $defaultValue = null): mixed
Read the player’s saved value for this game, or the default if absent. Use player ID 0 for data shared by all tables of the game.
set(string $key, int $playerId, mixed $value, int $ttl = 365): void
Save a JSON value. The limit is 64 KiB per key, player, and game. $ttl is in days, with a maximum of 365.
Only write this data at the end of the game, during its last action, to reduce conflicts between simultaneous tables.
delete(string $key, int $playerId): void
Delete a saved value.
Team data
getTeam(mixed $defaultValue = null): mixed
Read persistent data for the current table’s team and game. Return the default if the saved data is absent or null.
setTeam(mixed $value, int $ttl = 365): void
Save data for the team. The total limit is 64 KiB per team and game. Write it only during the last action, with a maximum lifetime of 365 days.
deleteTeam(): void
Delete the team’s saved data.
These methods communicate with the main site. Read the data sparingly, ideally once per player or team per game.
Campaign data and limits
Use this API when the game rules require persistent campaign or legacy progress. Store ordinary preferences through userPreferences and statistics through playerStats or tableStats.
Bound the amount of saved campaign data, and handle a storage-limit failure so it cannot prevent the game from ending. For example, during the last action:
try {
$this->bga->legacy->setTeam($campaign);
} catch (\feException $exception) {
if ($exception->getCode() !== FEX_legacy_size_exceeded) {
throw $exception;
}
// Apply your game's recovery strategy, such as keeping only essential progress.
// Do not retry with the same oversized value.
}
The current player-data storage checks each key’s JSON payload separately. Team storage uses one value for the group and is also subject to the size limit. Neither set nor setTeam may be used during game setup.
Example
$progress = $this->bga->legacy->get('campaign', $playerId);
$chapter = $progress->chapter ?? 1;