How to implement an 'at-any-time' action ?

Game development with Board Game Arena Studio
Post Reply
flopiano
Posts: 1
Joined: 10 March 2023, 17:29

How to implement an 'at-any-time' action ?

Post by flopiano »

I'm working on a game where, at any time (even during other players turn) it is possible for a player to do an exchange (e.g spend two fish to gain one wood, this does not affect other players in any way).

These kinds of exchange are quite rare (maybe once or twice per game, across all players),
but sometimes you want to do them between other players turns (because of some benefits you may gain when some actions are triggered).

Now, the game has quick turns, and I don't want to ask all players if they want to do an exchange at every player's turn.

I was thinking of an approach like this:

On the server I add a multiactive state between regular player states.
During that state the possible actions are "exchange" or "skip"

On the client I add a small box where users can click at any time when they want to do the action. The client just saves the click information as still "pending".

Now, the idea is that when the game enters the "exchange" state, the client will automatically execute an "exchange" action if there is a pending exchange otherwise it automatically sends a "skip" action.

The question is, where exactly can I make an ajaxcall like that ?

I tried both onEnteringState() adn onUpdateActionButtons() and in both cases I get errors like
"It is not your turn" or "please wait, an action is already in progress".
Then the client get stuck in the multiactive state with no possibility for the players to get unstuck
(once all players hit f5 the game proceeds).

Are there any examples of games that do something like this (with the possibility to look at their code) ?

Thanks in advance

F.
User avatar
Tisaac
Posts: 2350
Joined: 26 August 2014, 21:28

Re: How to implement an 'at-any-time' action ?

Post by Tisaac »

flopiano wrote: 19 March 2023, 15:31 I'm working on a game where, at any time (even during other players turn) it is possible for a player to do an exchange (e.g spend two fish to gain one wood, this does not affect other players in any way).

These kinds of exchange are quite rare (maybe once or twice per game, across all players),
but sometimes you want to do them between other players turns (because of some benefits you may gain when some actions are triggered).

Now, the game has quick turns, and I don't want to ask all players if they want to do an exchange at every player's turn.

I was thinking of an approach like this:

On the server I add a multiactive state between regular player states.
During that state the possible actions are "exchange" or "skip"

On the client I add a small box where users can click at any time when they want to do the action. The client just saves the click information as still "pending".

Now, the idea is that when the game enters the "exchange" state, the client will automatically execute an "exchange" action if there is a pending exchange otherwise it automatically sends a "skip" action.

The question is, where exactly can I make an ajaxcall like that ?

I tried both onEnteringState() adn onUpdateActionButtons() and in both cases I get errors like
"It is not your turn" or "please wait, an action is already in progress".
Then the client get stuck in the multiactive state with no possibility for the players to get unstuck
(once all players hit f5 the game proceeds).

Are there any examples of games that do something like this (with the possibility to look at their code) ?

Thanks in advance

F.
Check documentation, you have ways to bypass the active check, both on frontend and backend (checkPossibleAction instead of checkAction).
User avatar
quietmint
Posts: 265
Joined: 31 July 2017, 00:28

Re: How to implement an 'at-any-time' action ?

Post by quietmint »

Hardback has this. You can spend ink at any time to draw more cards. I created my own function checkActionCustom to deal with checking "can you use ink now?" and do not list the use ink action in the states.inc.php file.

https://github.com/quietmint/bga-hardba ... n.php#L294
https://github.com/quietmint/bga-hardba ... .php#L1609
User avatar
Lunalol
Posts: 446
Joined: 09 October 2016, 23:21

Re: How to implement an 'at-any-time' action ?

Post by Lunalol »

No deadlock problem ?
User avatar
quietmint
Posts: 265
Joined: 31 July 2017, 00:28

Re: How to implement an 'at-any-time' action ?

Post by quietmint »

You should obtain a lock on the BGA globals (e.g., next move id) in the globals table before touching anything in the players table. Like this:

https://github.com/quietmint/bga-hardba ... s.php#L410

Two players still can't take action at the exact same moment because of these BGA shared globals, but obtaining the lock here avoids a deadlock situation where neither player can progress (instead one players will fail fast and predictably).
Post Reply

Return to “Developers”