$this->bga->counterFactory
Create persistent numeric counters. Counters can notify front-end components automatically when their values change.
API
createTableCounter(string $name, ?int $min = 0, ?int $max = null): TableCounter
Create one counter shared by the table. See TableCounter for initialization, value updates, and front-end integration.
createPlayerCounter(string $name, ?int $min = 0, ?int $max = null, CounterVisibility $visibility = CounterVisibility::VISIBLE, bool $useNo = false, ?bool $strict = null): PlayerCounter
Create a counter with a distinct value for each player. See PlayerCounter for its API and examples.
Both methods default to a minimum of 0 and no maximum. Set a bound to null to remove it. Names must be unique within each counter type.
For player counters, import Bga\GameFramework\Components\Counters\CounterVisibility and choose VISIBLE, SELF, or HIDDEN. $useNo selects player numbers instead of IDs. If $strict is omitted, it is enabled for player numbers and disabled for IDs.
Example
Create and declare your counter properties in Game. In the constructor, after parent::__construct():
$this->round = $this->bga->counterFactory->createTableCounter('round', min: 1);
$this->energy = $this->bga->counterFactory->createPlayerCounter('energy', useNo: true);
Call each counter’s initDb in setupNewGame before using it. See the component pages for the required initialization arguments.
The framework already provides playerScore and playerScoreAux; use those instances for scores.