Page 1 of 1

Help with transitions

Posted: 09 March 2025, 11:17
by ric1950
I am developing my first BGA game - it has been a big learning curve.
I am having an issue with an aspect of transitions from one state to the next. The relevant part of the states.inc.php is:

// Phase 1 (Multiplayer)
STATE_PHASE_1 => array( // 20
"name" => "playerTurnPhase1",
"description" => clienttranslate('Waiting for other players to place their shape or pass'),
"descriptionmyturn" => clienttranslate('You must place the first shape in one of the grids or pass'),
"type" => "multipleactiveplayer",
"action" => "stSetupPhase1",
"updateGameProgression" => true,
"possibleactions" => array("actProcessPlaceShape", "actPass"),
"transitions" => array("completePhase1" => STATE_PHASE_2, "gameEnd" => STATE_END_GAME)
),

// Phase 2 (Multiplayer)
STATE_PHASE_2 => array( // 30
"name" => "playerTurnPhase2",
"description" => clienttranslate('Waiting for other players to place their shape or pass'),
"descriptionmyturn" => clienttranslate('You must place the second shape in one of the remaining grids or pass'),
"type" => "multipleactiveplayer",
"action" => "stSetupPhase2",
"updateGameProgression" => true,
"possibleactions" => array("actProcessPlaceShape", "actPass"),
"transitions" => array("completePhase2" => STATE_PHASE_3, "gameEnd" => STATE_END_GAME)
),


In the transition from STATE_PHASE_1 to STATE_PHASE_2 (after both players have placed and confirmed the position) the stSetupPhase2() function does certain things (including a self::notifyAllPlayers() call) which are being undone by by the actProcessPlaceShape() function which should be called during STATE_PHASE_1,
I would expect actProcessPlaceShape() would run before the transition to next state and beforestSetupPhase() runs.
The actProcessPlaceShape() is called when a player places their shape and works as expected when the first player (in a two player game) confirms their shape position.

I have struggled with this for too long so anny help or suggestions would be most welcome.

Re: Help with transitions

Posted: 10 March 2025, 14:40
by RicardoRix
may help to game an intermediate game state to transition from one to the other state.
type => game.

Re: Help with transitions

Posted: 11 March 2025, 23:25
by ric1950
Thanks for the suggestion RicardoRix. I had thought of that myself, but when I did add an extra state between states it didn't help.

I have now sorted out the issue. I did suspect something else and a ChatGPT search came up with:

Possible Causes of Out-of-Sequence Calls in BGA:
Asynchronous Execution Issues:

Some game actions (notifyAllPlayers, UI updates, AJAX calls) are asynchronous. If you assume they complete immediately, but they actually take time, your code might execute in the wrong order.

This is exactly what was happening When I added a delay to to my notifyAllPlayers call execution it gave the previous routine ( actProcessPlaceShape() ) a chance to complete and so things are now happening in the correct order.

I hope this helps someone else.