Page 1 of 1

Executing action when not active

Posted: 08 July 2026, 05:53
by RichardSPeters
Edit:Take first couple few comments with grain of salt as I had nade a few incorrect assumptions!

Working my way through a v simple first game which has a multi player component - i.e. Player Turn state is MULTIPLE_ACTIVE_PLAYER

Can anyone point me in the direction of games (the simpler the better) developed using the new framework that have a multi player component.

That way I can have a dig through the code and try and fill in the missing pieces I have read in the wiki (and failing that post a succinct question here).

Thanks

Re: Multi Player Players

Posted: 08 July 2026, 09:53
by tchobello
hello

Can you be more specific about what you are trying to achieve in multiplayer mode?
There are many possible approaches and implementations depending on the game mechanics.

Re: Multi Player Players

Posted: 08 July 2026, 22:51
by RichardSPeters
Lets imagine a game of SNAP being implemented.

So for SNAP if we have three players Bilbo, Gollum and Frodo where Bilbo is currently the active player and the Jack of Spades is on the table and the onEnteringState in playerTurn.js looks like this

Code: Select all

  onEnteringState(args, isCurrentPlayerActive) {
    if (isCurrentPlayerActive) {
      bga.statusBar.addActionButton(
        _("Play Card " + source),
        () => this.game.playCard(),
        {
          id: "playCardButton",
        },
      );
    }

    bga.statusBar.addActionButton(_("SNAP"), () => this.game.snap(), {
      id: "snapButton",
    });
  }
Bilbo can see two button on his status bar. "Play Card" and "SNAP". Gollum and Frodo can see one button on their status bar "SNAP"

Now if Bilbo hit's the "Play CArd" button and the Jack of Diamonds is played, Gollum is now made the active player.

Gollum can now see two button on his status bar. "Play Card" and "SNAP". Bilbo and Frodo can see one button on their status bar "SNAP".

If state type of PlayerTurn.php is ACTIVE_PLAYER then if Bilbo or Frodo click the SNAP button then the error message 'This is not your turn' appears and command is not sent to server. Gollum on the other hand is fine.

If state type of PlayerTurn.php is MULTIPLE_ACTIVE_PLAYER then if Bilbo or Frodo can click the SNAP button BUT in onEnteringState isCurrentPlayerActive is always false and setting the title is an issie as ${actplayer} is not available.

Re: Multi Player Players

Posted: 09 July 2026, 05:53
by RichardSPeters
Ok - figured it out. What I need to do is pass
{ checkAction: false },
as a paramenter to the performAction call.

This stops the error message 'This is not your turn' appearing BUT now I am getting "The server reported an error."

Re: Multi Player Players

Posted: 09 July 2026, 06:46
by RichardSPeters
Sorted (after some prodding in the right direction).

Client Side code to add a button that can be clicked when not your turn is

this.bga.statusBar.addActionButton(_("~ SNAP ~"), () =>
this.bga.actions.performAction("actSNAP", {}, { checkAction: false }),
);

Server side code is

use Bga\GameFramework\Actions\CheckAction;
...
#[CheckAction(false)]
public function actSNAP()
{
$game = $this->game;

$game->notify->all('xxx', "start xxx");
}

Re: Multi Player Players

Posted: 09 July 2026, 07:32
by tchobello
Glad you found a way!

You might want to rename the topic, since it now reads like a "How-to" guide, thanks to you.