$this->bga->debug
Use zombie behavior to advance a test game automatically. Implement the zombie methods for your states before using this helper.
API
playUntil(callable $fn)
Check the callback before each iteration, starting with count 0. While it returns false, increment the count and run the zombie method for each active player. Stop when the callback returns true.
// Run up to 10 iterations of automatic play.
$this->bga->debug->playUntil(fn(int $count): bool => $count >= 10);
An iteration may advance several players. It is not necessarily one turn. Choose a condition that can become true even if the game stops advancing.
Environment
Bga\GameFramework\Table::getBgaEnvironment() returns studio or prod for environment-specific debugging hooks.
This lets you test changes in Studio, such as adding an expansion, without exposing them in production.
Debug functions
Custom debug functions let you prepare a specific game situation without playing through an entire game, for example to test a particular card.
Define these methods in modules/php/Game.php and prefix their names with debug_. BGA detects them and their parameters automatically. Functions with parameters appear with ... in the Studio debug menu and open a dialog for entering values. Functions without parameters run immediately.
Changing a card's type
Import Bga\GameFramework\Actions\Debug to use #[Debug(reload: true)]. This attribute reloads the interface after the function runs, so it displays the updated game data.
use Bga\GameFramework\Actions\Debug;
#[Debug(reload: true)]
function debug_setCardType(int $id, int $type, int $typeArg = 0)
{
$this->DbQuery("UPDATE `card` SET `card_type` = $type, `card_type_arg` = $typeArg WHERE `card_id` = $id");
}
This example uses the standard Deck table's column names. Adapt the table and columns to your game's database model.
Moving to another state
Jump to a state to simulate a particular point in the game, such as the end of a player's turn:
public function debug_goToState(int $state = ST_NEXT_PLAYER)
{
$this->gamestate->jumpToState($state);
}
ST_NEXT_PLAYER and ST_END_GAME in these examples are constants defined by your game. Replace them with the appropriate state IDs or constants.
Playing automatically
Use playUntil to advance the game through zombie moves until a condition is met. Your states must implement their zombie methods.
For example, reach 50% progression so you can test conceding. Stop at game end or after 100 iterations if the progression threshold has not been reached:
function debug_playToFiftyPercent()
{
$this->bga->debug->playUntil(fn(int $count) =>
$this->gamestate->getCurrentMainStateId() >= ST_END_GAME
|| $this->getGameProgression() >= 50
|| $count >= 100
);
}
To inspect the end of a round, play until the round number increases. In this example, getCurrentRound() is a game-defined helper:
function debug_playToEndRound()
{
$round = $this->getCurrentRound();
$this->bga->debug->playUntil(fn(int $count) => $this->getCurrentRound() > $round);
}
To advance to a specific player's turn, accept their player ID as a parameter:
function debug_playUntilTurnOf(int $playerId)
{
$this->bga->debug->playUntil(fn(int $count) => (int)$this->getActivePlayerId() === $playerId);
}
To advance to the turn of the player running the debug function:
function debug_playUntilMyTurn()
{
$this->bga->debug->playUntil(fn(int $count) =>
(int)$this->getActivePlayerId() === (int)$this->getCurrentPlayerId()
);
}
Testing a database upgrade
Call your game's upgradeTableDb method with the version you want to test: