[Resolved] Can't call getCurrentPlayerName in some states
Posted: 20 January 2021, 20:45
Hi BGA studio gurus,
I'm about 40 hours into programming this game, learning the BGA studio framework
and the game states model. Most things are working for me, but I ran into this weird condition
and I'm hoping someone can tell me why it is happening.
Apparently I can't call getCurrentPlayerName() in some game states and I don't understand
why. I set up a few states: startRound, playerTurn, nextPlayer, endRound and some associated
state functions. Within stPlayerTurn, I cannot call self::getCurrentPlayerName() or I get an error
and the game doesn't even get created.
Unexpected error: Propagating error from GS 1 (method: createGame): Fatal error during xxx setup: Not logged
Unexpected error: Invalid player number for this game: 1
Can you explain why calling getCurrentPlayerName() doesn't work? Is stPlayerTurn getting called before the
game is fully initialized? I'm calling $this->activateNextPlayer() inside setupNewGame(). I would assume
that the state machine is not started and no state functions are called until after setupNewGame(). Is this wrong?
Help me out here, please. I've searched the forum but I don't see an answer.
Thanks much, Brian
Portions of states.inc.php:
Javascript console log shows:
Game log displays:
stPlayerTurn state function:
I'm about 40 hours into programming this game, learning the BGA studio framework
and the game states model. Most things are working for me, but I ran into this weird condition
and I'm hoping someone can tell me why it is happening.
Apparently I can't call getCurrentPlayerName() in some game states and I don't understand
why. I set up a few states: startRound, playerTurn, nextPlayer, endRound and some associated
state functions. Within stPlayerTurn, I cannot call self::getCurrentPlayerName() or I get an error
and the game doesn't even get created.
Unexpected error: Propagating error from GS 1 (method: createGame): Fatal error during xxx setup: Not logged
Unexpected error: Invalid player number for this game: 1
Can you explain why calling getCurrentPlayerName() doesn't work? Is stPlayerTurn getting called before the
game is fully initialized? I'm calling $this->activateNextPlayer() inside setupNewGame(). I would assume
that the state machine is not started and no state functions are called until after setupNewGame(). Is this wrong?
Help me out here, please. I've searched the forum but I don't see an answer.
Thanks much, Brian
Portions of states.inc.php:
Code: Select all
$machinestates = array(
// The initial state. Please do not modify.
1 => array(
"name" => "gameSetup",
"description" => "",
"type" => "manager",
"action" => "stGameSetup",
"transitions" => array(
"startRound" => 10
)
),
// Start of the round of player turns. Advance the round number.
10 => array(
"name" => "startRound",
"description" => "",
"type" => "game",
"action" => "stStartRound",
"transitions" => array(
"playerTurn" => 20,
"endGame" => 99
)
),
// Start of a player turn.
20 => array(
"name" => "playerTurn",
"type" => "activeplayer",
"action" => "stPlayerTurn",
"description" => clienttranslate('${actplayer} must choose an action.'),
"descriptionmyturn" => clienttranslate('${you} must choose an action: '),
"possibleactions" => array( "pass" ),
"transitions" => array(
"playerTurn" => 20,
"nextPlayer" => 80,
"endRound" => 90,
"endGame" => 99
)
),Code: Select all
Starting game setup
notifications subscriptions setup
Ending game setup
onUpdateActionButtons: playerTurn
Entering state: playerTurn
onPass event handler
Leaving state: playerTurn
onUpdateActionButtons: nextPlayer
Entering state: nextPlayer
Leaving state: nextPlayer
onUpdateActionButtons: endRound
Entering state: endRound
Leaving state: endRound
onUpdateActionButtons: startRound
Entering state: startRound
Leaving state: startRound
Code: Select all
Starting round 1
Start of turn
brianhannamn0 passed
End of turn
Start of turn
brianhannamn1 passed
End of turn
End of round 1
Starting round 2
Code: Select all
function stPlayerTurn()
{
// Get the current player
// Can't do this, it throws an error that's very hard to debug. Why?
//$player_name = self::getCurrentPlayerName();
// Notify players of the turn
self::notifyAllPlayers( "announceStartTurn", clienttranslate( "Start of turn" ), array() );
// (very often) go to another gamestate
//$this->gamestate->nextState( 'drawEventCard' );
//$this->gamestate->nextState( 'advanceLava' );
//$this->gamestate->nextState( 'nextPlayer' );
}