Other active player states do not transition properly after playerTurn state has happened

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

Other active player states do not transition properly after playerTurn state has happened

Post by developgame »

Thanks for any advice, suggestions, help!
My state 'assignGuestRoom' works well repeately before "playTurn" state runs
BGA requestSQL logs - transition 'admitGuest' to 'assignGuestRoom' works correctly just after gameSetup and before state "playerTurn"- note only 1 after jump to nextState1

Code: Select all

13/05 01:11:58 [info] [T378668] [50.92.223.190] [2323322/developGames1] nextState with action: 'admitGuest'1
13/05 01:11:58 [info] [T378668] [50.92.223.190] [2323322/developGames1] jump to state 31

13/05 01:11:58 [info] [T378668] [50.92.223.190] [2323322/developGames1] New game state: 'admitGuest'1
13/05 01:11:58 [info] [T378668] [50.92.223.190] [2323322/developGames1] nextState with action: 'assignGuestRoom'1
13/05 01:11:58 [info] [T378668] [50.92.223.190] [2323322/developGames1] jump to state 21
13/05 01:11:58 [info] [T378668] [50.92.223.190] [2323322/developGames1] New game state: 'assignGuestRoom'1

13/05 01:11:58 [info] [T378668] [50.92.223.190] [2323322/developGames1] after jump to nextState1
13/05 01:11:58 [info] [T378668] [50.92.223.190] [2323322/developGames1] checkZombieTurn1
13/05 01:11:58 [info] [T378668] [50.92.223.190] [2323322/developGames1] after jump to nextState1
13/05 01:11:58 [info] [T378668] [50.92.223.190] [2323322/developGames1] Sending notifications1
After "playerTurn" state has run, active player states no longer work.
BGA requestSQL logs - after state "playerTurn" transition 'admitGuest' to 'assignGuestRoom' never happens - the SQL logs shows 3 'after jump to nextState1' - giving me state 'playerTurn' instead

Code: Select all

13/05 01:08:43 [info] [T376668] [50.92.223.190] [2323322/developGames1] nextState with action: 'endRound'1
13/05 01:08:43 [info] [T376668] [50.92.223.190] [2323322/developGames1] jump to state 121

13/05 01:08:43 [info] [T376668] [50.92.223.190] [2323322/developGames1] New game state: 'endRound'1
13/05 01:08:43 [info] [T376668] [50.92.223.190] [2323322/developGames1] nextState with action: 'admitGuest'1
13/05 01:08:43 [info] [T376668] [50.92.223.190] [2323322/developGames1] jump to state 31
13/05 01:08:43 [info] [T376668] [50.92.223.190] [2323322/developGames1] New game state: 'admitGuest'1
13/05 01:08:43 [info] [T376668] [50.92.223.190] [2323322/developGames1] nextState with action: 'assignGuestRoom'1
13/05 01:08:43 [info] [T376668] [50.92.223.190] [2323322/developGames1] jump to state 21
13/05 01:08:43 [info] [T376668] [50.92.223.190] [2323322/developGames1] New game state: 'assignGuestRoom'1
13/05 01:08:43 [info] [T376668] [50.92.223.190] [2323322/developGames1] after jump to nextState1
13/05 01:08:43 [info] [T376668] [50.92.223.190] [2323322/developGames1] after jump to nextState1
13/05 01:08:43 [info] [T376668] [50.92.223.190] [2323322/developGames1] after jump to nextState1
13/05 01:08:43 [info] [T376668] [50.92.223.190] [2323322/developGames1] nextState with action: 'playerTurn'1
13/05 01:08:43 [info] [T376668] [50.92.223.190] [2323322/developGames1] DB rollback: action cancelled1
13/05 01:08:43 [error] [T376668] [50.92.223.190] [2323322/developGames1] Unexpected exception: This transition (playerTurn) is impossible at this state (2)#
#0 /var/tournoi/release/games/bi/999999-9999/bi.game.php(560): Gamestate->nextState()#
#1 /var/tournoi/release/tournoi-220510-1000-gs/www/game/module/table/gamestate.game.php(502): BI->stNextPlayer()#
#2 /var/tournoi/release/tournoi-220510-1000-gs/www/game/module/table/gamestate.game.php(398): Gamestate->jumpToState()#
#3 /var/tournoi/release/games/bi/999999-9999/modules/traveler.php(178): Gamestate->nextState()#
#4 /var/tournoi/release/games/bi/999999-9999/bi.game.php(462): BI->nextGameStateFromPlayerTurnCheckAnnexArray()#

BGA requestSQL logs going directly from state "endRound" to an activePlayer State "payAccomplice" causes error " "Impossible to change active player during activeplayer type state". change active player code is in state endRound method - state 'payAccomplice' has no associated code so no activeplayer change should happen, but the log shows activeNextPlayer happens here

Code: Select all

18/05 23:31:04 [info] [T380840] [50.92.220.52] [2323321/developGames0] nextState with action: 'endRound'1
18/05 23:31:04 [info] [T380840] [50.92.220.52] [2323321/developGames0] jump to state 121


18/05 23:31:04 [info] [T380840] [50.92.220.52] [2323321/developGames0] New game state: 'endRound'1
18/05 23:31:04 [info] [T380840] [50.92.220.52] [2323321/developGames0] nextState with action: 'payAccomplice'1
18/05 23:31:04 [info] [T380840] [50.92.220.52] [2323321/developGames0] jump to state 131
FROM player 1
18/05 23:31:04 [info] [T380840] [50.92.220.52] [2323321/developGames0] New game state: 'payAccomplice'1
WHERE player_id IN ('2323322') 1
18/05 23:31:04 [info] [T380840] [50.92.220.52] [2323321/developGames0] after jump to nextState1
18/05 23:31:04 [info] [T380840] [50.92.220.52] [2323321/developGames0] activeNextPlayer1
18/05 23:31:04 [info] [T380840] [50.92.220.52] [2323321/developGames0] DB rollback: action cancelled1
18/05 23:31:04 [error] [T380840] [50.92.220.52] [2323321/developGames0] Unexpected exception: Impossible to change active player during activeplayer type state#
#0 /var/tournoi/release/tournoi-220513-1000-gs/www/game/module/table/table.game.php(1291): Gamestate->changeActivePlayer()#
#1 /var/tournoi/release/games/bi/999999-9999/bi.game.php(583): Table->activeNextPlayer()#
#2 /var/tournoi/release/tournoi-220513-1000-gs/www/game/module/table/gamestate.game.php(502): BI->stPayAccomplice()#
#3 /var/tournoi/release/tournoi-220513-1000-gs/www/game/module/table/gamestate.game.php(398): Gamestate->jumpToState()#
#4 /var/tournoi/release/games/bi/999999-9999/bi.game.php(569): Gamestate->nextState()#
#5 /var/tournoi/release/tournoi-220513-1000-gs/www/game/module/table/gamestate.game.php(502): BI->stNextPlayer()#
#6 /var/tournoi/release/tournoi-220513-1000-gs/www/game/module/table/gamestate.game.php(398): Gamestate->jumpToState()#
#7 /var/tournoi/release/games/bi/999999-9999/modules/traveler.php(141): Gamestate->nextState()#
#8 /var/tournoi/release/games/bi/999999-9999/bi.game.php(473): BI->nextGameStateFromPlayerTurnCheckAnnexArray()#
#9 /var/tournoi/release/games/bi/999999-9999/bi.action.php(55): BI->playerAction()#

Here are my states

Code: Select all

 
$machinestates = array(

    1 => array(
        "name" => "gameSetup",
        "description" => "",
        "type" => "manager",
        "action" => "stGameSetup",
        "transitions" => array( "" => 2 )
    ),
    
    2 => array(
    	"name" => "assignGuestRoom",
    	"description" => clienttranslate('${actplayer} must place guest in room'),
    	"descriptionmyturn" => clienttranslate('${you} must place guest in room'),
    	"type" => "activeplayer",
    	"possibleactions" => array( "admitGuest" ),
    	"transitions" => array( "admitGuest" => 3 )
    ),
    3 => array(
        "name" => "admitGuest",
        "description" => '',
        "type" => "game",
        "action" => "stAdmitGuest",
        "updateGameProgression" => true,   
        "transitions" => array( "assignGuestRoom" => 2, "playerTurn" => 4 )
    ), 
    4 => array(
    		"name" => "playerTurn",
    		"description" => clienttranslate('${actplayer} select guest then hand payment then choose action'),
    		"descriptionmyturn" => clienttranslate('${you} select guest then hand payment then choose action'),
    		"type" => "activeplayer",
    		"possibleactions" => array( "bribed", "killed", "built","burried", "pass"  ),
    		"transitions" => array( "nextPlayer" => 5 )
    ),
    5 => array(
        "name" => "nextPlayer",
        "description" => '',
        "type" => "game",
        "action" => "stNextPlayer",
        "updateGameProgression" => true,   
        "transitions" => array( "playerTurn" => 4,"endRound" => 12 )
    ),  

   12 => array(
        "name" => "endRound",
        "description" => '',
        "type" => "game",
        "action" => "stPayAccomplice",
        "updateGameProgression" => true,   
        "transitions" => array( "admitGuest" => 3, "payAccomplice" => 13, "gameEnd" => 99 )
    ), 
    13 => array(
    		"name" => "payAccomplice",
    		"description" => clienttranslate('${actplayer} must select accomplice to remove'),
    		"descriptionmyturn" => clienttranslate('${you}  must select accomplice to remove'),
    		"type" => "activeplayer",
    		"possibleactions" => array( "remove"  ),
    		"transitions" => array( "endRound" => 12  )
    ),
  
    99 => array(
        "name" => "gameEnd",
        "description" => clienttranslate("End of game"),
        "type" => "manager",
        "action" => "stGameEnd",
        "args" => "argGameEnd"
    )

);


Here is my code game.php code

Code: Select all

    function admitGuest( $info ) {  
		$this->gamestate->nextState( 'admitGuest' );
	}
	

    function stAdmitGuest() { 

		$traveller = self::incGameStateValue( 'traveller_day_count', 1 );
		$num_players = self::getPlayersNumber();
		$num_travellers  =  (  $num_players < 4 ) ? $num_players + 3 : $num_players + 4;

		if ( $traveller <  $num_travellers ) {
			$this->gamestate->nextState( 'assignGuestRoom' );			
		} else {
			$this->gamestate->nextState( 'playerTurn' );
		}  

    } 

	function stNextPlayer() {  // triggered after state "playerTurn"
		$this->activeNextPlayer();
		if ( $action_round > 1 ) { 
				$this->gamestate->nextState( 'endRound' );
		} 
		$this->gamestate->nextState( 'playerTurn' );
	}
	
	function stPayAccomplice() { // method for endRound state
		//some code here...
		while ( $starting_player_pay_status == 0 ) { 
			//some code here
			
			if ( $starting_player_id == $player_id ) self::setGameStateInitialValue('start_player_paid', 1 );
			$starting_player_pay_status = self::getGameStateValue(  'start_player_paid');
			if ( $wages > $payment[0] ) $this->gamestate->nextState( 'payAccomplice' );
		}
		
		if  ( $starting_player_pay_status != 0 ) {
			$this->gamestate->changeActivePlayer( $starting_player_id );
			$this->gamestate->nextState( 'admitGuest' );
		}
	}


I am grateful for any help! Thanks!
User avatar
ufm
Posts: 2039
Joined: 06 January 2017, 08:38

Re: Other active player states do not transition properly after playerTurn state has happened

Post by ufm »

Do not call nextState multiple times.
Use if-else, switch, a variable storing target state, or something similar to call nextState only once per state transition.
User avatar
developgame
Posts: 107
Joined: 15 June 2020, 20:56

Re: Other active player states do not transition properly after playerTurn state has happened

Post by developgame »

ufm wrote: 19 May 2022, 10:53 Do not call nextState multiple times.
Use if-else, switch, a variable storing target state, or something similar to call nextState only once per state transition.
Thanks for your reply, ufm! and your attempts to help me.


My post is not very clear.
what I am trying to say is that the BGA studio framework is jumping multiple state whenever I call an activePlayer state other than activePlayer state 'playerTurn'. I can see this in the "BGA requestSQL logs" with the ' after jump to nextState1' lines in the log. I do not have or call 'nextState' state.

The framework is also activating the next player after I call an activePlayer state and I would get error message "Impossible to change active player during activeplayer type state". In the "BGA requestSQL logs" you can see that.

Explaining to you what I was trying to say helped with making my post more clear. Thanks!
Okay with you if I kill this post in a few days and create another one?
User avatar
TomFCG
Posts: 18
Joined: 08 July 2019, 10:24

Re: Other active player states do not transition properly after playerTurn state has happened

Post by TomFCG »

In your function stNextPlayer you are calling $this->gamestate->nextState( 'endRound' ); followed by $this->gamestate->nextState( 'playerTurn' ); You may be missing an "else".
User avatar
developgame
Posts: 107
Joined: 15 June 2020, 20:56

Re: Other active player states do not transition properly after playerTurn state has happened

Post by developgame »

TomFCG wrote: 20 May 2022, 00:54 In your function stNextPlayer you are calling $this->gamestate->nextState( 'endRound' ); followed by $this->gamestate->nextState( 'playerTurn' ); You may be missing an "else".
Thanks TomFCG
Yes! Found the problem! thanks!

Problem was if I did not set the condition for the states to happen, they will happen even if I called another state. So what happened was when I called state " admitGuest", BGA studio framework then called state "playerTurn" and this was not what I wanted.
like you said, I needed to set the condition in which the two states were called.

Problem solved!
Post Reply

Return to “Developers”