Executing action when not active

Game development with Board Game Arena Studio
Post Reply
User avatar
RichardSPeters
Posts: 18
Joined: 27 August 2021, 23:14

Executing action when not active

Post 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
Last edited by RichardSPeters on 09 July 2026, 10:58, edited 1 time in total.
User avatar
tchobello
Posts: 693
Joined: 18 March 2012, 13:19

Re: Multi Player Players

Post 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.
User avatar
RichardSPeters
Posts: 18
Joined: 27 August 2021, 23:14

Re: Multi Player Players

Post 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.
User avatar
RichardSPeters
Posts: 18
Joined: 27 August 2021, 23:14

Re: Multi Player Players

Post 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."
User avatar
RichardSPeters
Posts: 18
Joined: 27 August 2021, 23:14

Re: Multi Player Players

Post 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");
}
User avatar
tchobello
Posts: 693
Joined: 18 March 2012, 13:19

Re: Multi Player Players

Post 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.
Post Reply

Return to “Developers”