How to implement undo in a MULTIPLE_ACTIVE_PLAYER state?

Game development with Board Game Arena Studio
Post Reply
User avatar
developgame
Posts: 110
Joined: 15 June 2020, 20:56

How to implement undo in a MULTIPLE_ACTIVE_PLAYER state?

Post by developgame »

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:

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);
}
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.
User avatar
Tisaac
Posts: 2779
Joined: 26 August 2014, 21:28

Re: How to implement undo in a MULTIPLE_ACTIVE_PLAYER state?

Post by Tisaac »

No need to keep them active, you can do action when inactive as long as you use the correct settings explained in the doc
User avatar
tchobello
Posts: 731
Joined: 18 March 2012, 13:19

Re: How to implement undo in a MULTIPLE_ACTIVE_PLAYER state?

Post by tchobello »

BGA guidelines strongly suggest to use Confirm instead of Undo.
User avatar
oBsiDiaN
Posts: 14
Joined: 25 April 2020, 03:19

Re: How to implement undo in a MULTIPLE_ACTIVE_PLAYER state?

Post by oBsiDiaN »

Confirm doesn't help when you want to allow players in multiactive to undo their action.

I haven't done this myself but I understand the approach is to show the undo button for non-active players and allow the action using

Code: Select all

#[CheckAction(false)]
see here for details

https://doc.studio.boardgamearena.com/f ... tion-check
User avatar
developgame
Posts: 110
Joined: 15 June 2020, 20:56

Re: How to implement undo in a MULTIPLE_ACTIVE_PLAYER state?

Post by developgame »

Thank you so much to all three of you for taking the time to help me out with this! I really appreciate the insights from this community.
@Tisaac — Thank you for pointing that out! I completely missed that inactive players can still trigger actions with the right settings. Knowing I don't have to fight the framework to keep them multiactive saves me a huge headache and makes the architecture much cleaner.
@tchobello — Thank you for the reminder about the BGA UX guidelines! Keeping the standard "Confirm" pattern in mind is always great advice for keeping the player experience consistent across the platform.
@oBsiDiaN — Thank you for the exact attribute (#[CheckAction(false)]) and the documentation link! Seeing how that connects directly to Tisaac's point gives me the exact blueprint I need to show the undo button to non-active players and let the framework handle the avatar states properly.

Thanks again for steering me in the right direction—I'm excited to refactor this cleanly now!
Post Reply

Return to “Developers”