How to implement undo in a MULTIPLE_ACTIVE_PLAYER state?
Posted: 23 November 2026, 21:22
Thank you for any suggestions
I am implementing an undo feature in a StateType::MULTIPLE_ACTIVE_PLAYER state.
All players initially need to remain active so they can:
Submit a guess.
Undo their submitted guess.
Submit again after undoing.
My server action currently stores the selected guess in a global and notifies all clients:
When a player submits, they should be able to undo and remain eligible to submit again.
What is the recommended way to keep submitted players framework-active until all players have submitted?
I understand that setPlayerNonMultiactive() would deactivate the player and prevent undo, so I have not used it. I also do not want to call setAllPlayersMultiactive() on every undo if that would affect the remaining players.
How should the framework state and onUpdateActionButtons() be used to support this pattern?
In particular:
How do active and submitted states remain separate?
Can individual players remain framework-active after submitting?
If an individual player can be inactive while retaining an undo action, what is the supported API for restoring them?
Should submission status be kept in the existing global, or should player multiactive status itself be updated and queried?
What callbacks should handle avatar/status synchronization after submit and undo?
Client observation: When a player submits, BGA can render the normal/emblem avatar and my TypeScript successfully changes avatar_active_<playerId> into avatar_<playerId>. When they undo, however, TypeScript cannot reliably restore avatar_active_<playerId> because BGA/redrawing the player panel overwrites the local DOM mutation.
My desired behavior:
The player should remain framework-active after submission so the undo action remains possible. A submitted state should be tracked separately from BGA’s multiactive framework state.
I am implementing an undo feature in a StateType::MULTIPLE_ACTIVE_PLAYER state.
All players initially need to remain active so they can:
Submit a guess.
Undo their submitted guess.
Submit again after undoing.
My server action currently stores the selected guess in a global and notifies all clients:
Code: Select all
<?php
#[PossibleAction]
public function actDone(string|null $id, int $current_player_id, array $args)
{
$guess_UX_ID = $id !== null && $id !== '' ? $id[0] : null;
$selected_guess_id = $id !== null ? substr($id, 1) : null;
$this->game->notifyGuessSelected($current_player_id, $guess_UX_ID);
$this->game->dbUpdatePlayerGuessID(
$current_player_id,
$selected_guess_id
);
$this->game->setPlayerSubmission(
$current_player_id,
$guess_UX_ID
);
if ($this->game->areAllPlayersSubmitted()) {
$this->game->notifyAllSubmission();
$this->gamestate->setAllPlayersNonMultiactive(
STATE_GET_GROUP_GUESS
);
$this->game->clearPlayerSubmission();
}
}
#[PossibleAction]
public function actUndo(int $current_player_id): void
{
$this->game->dbUpdatePlayerGuessID($current_player_id, null);
$this->game->setPlayerSubmission($current_player_id, null);
$this->game->notifySubmissionChange($current_player_id, false);
}
What is the recommended way to keep submitted players framework-active until all players have submitted?
I understand that setPlayerNonMultiactive() would deactivate the player and prevent undo, so I have not used it. I also do not want to call setAllPlayersMultiactive() on every undo if that would affect the remaining players.
How should the framework state and onUpdateActionButtons() be used to support this pattern?
In particular:
How do active and submitted states remain separate?
Can individual players remain framework-active after submitting?
If an individual player can be inactive while retaining an undo action, what is the supported API for restoring them?
Should submission status be kept in the existing global, or should player multiactive status itself be updated and queried?
What callbacks should handle avatar/status synchronization after submit and undo?
Client observation: When a player submits, BGA can render the normal/emblem avatar and my TypeScript successfully changes avatar_active_<playerId> into avatar_<playerId>. When they undo, however, TypeScript cannot reliably restore avatar_active_<playerId> because BGA/redrawing the player panel overwrites the local DOM mutation.
My desired behavior:
The player should remain framework-active after submission so the undo action remains possible. A submitted state should be tracked separately from BGA’s multiactive framework state.