$this->bga->tableStats
Manage statistics with one value for the whole table. Declare the statistics in the table section of stats.jsonc.
API
init(string|array $nameOrNames, int|float|bool $value): void
Initialize one statistic, or several names with the same value. Call this during setupNewGame.
get(string $name): int|float|bool
Read a value using the type declared in the configuration.
set(string $name, int|float|bool $value): void
Replace the value.
inc(string $name, int|float $delta): void
Add a signed amount to a numeric statistic. Boolean statistics cannot be incremented.
Example
// In setupNewGame:
$this->bga->tableStats->init('rounds', 0);
// When a round finishes:
$this->bga->tableStats->inc('rounds', 1);
For statistics associated with individual players, use playerStats.
Optional statistics
Initialize the statistics that apply to the selected game variant. A statistic that is never initialized or updated stays undefined and is excluded from cumulative statistics; initializing it to zero records a real zero. See statistics initialization.
Initializing several values and computing a derived value
// In setupNewGame, with these names declared in stats.jsonc:
$this->bga->tableStats->init(['rounds', 'tilesPlaced'], 0);
$this->bga->tableStats->init('tilesPerRound', 0.0);
// When computing final statistics:
$rounds = $this->bga->tableStats->get('rounds');
$tiles = $this->bga->tableStats->get('tilesPlaced');
$this->bga->tableStats->set('tilesPerRound', $rounds > 0 ? $tiles / $rounds : 0.0);
These methods replace the table forms of initStat, setStat, incStat, and getStat. In particular, the modern set and inc take the statistic name before the value or delta.