Skip to content

$this->bga->logs

Use this API when implementing undo to remove the log entries associated with reverted moves.

API

getCurrentMoveId(): int

Return the current move identifier during an action. Save this alongside the game data needed to undo that action.

remove(int $startMoveId): void

Delete logs for the saved move and all later moves. The framework sends bgaRemoveLogs to remove those entries from the interface and suppresses database recording of subsequent notifications in that request.

Restore the game data to its previous position before calling remove. Removing logs alone does not undo database changes or rebuild the interface.

// When recording an action for undo:
$moveId = $this->bga->logs->getCurrentMoveId();

// When undoing, after restoring the saved game data:
$this->bga->logs->remove($moveId);

Custom undo example

Save the move ID together with the information needed to restore the database. For example, after moving a tile in a Game action:

$this->bga->globals->set('undoTileMove', [
    'tileId' => $tileId,
    'previousLocation' => $previousLocation,
    'moveId' => $this->bga->logs->getCurrentMoveId(),
]);

In the undo action, restore the tile and send the notifications that restore the interface before removing the logs:

$undo = $this->bga->globals->get('undoTileMove');
// Restore the tile to $undo['previousLocation'] in the database.
// Notify the clients so their interfaces match the restored data.
$this->bga->globals->delete('undoTileMove');
$this->bga->logs->remove($undo['moveId']);

Make remove the final explicit logging operation of the undo. Do not perform another gameplay action or send another game notification afterward; any required state transition should only return players to the restored decision point.

This API manages logs for a custom undo implementation. For the built-in database savepoint API and its configuration, see Undo moves and the BGA Undo policy.