getNextPlayerTable and when to call it [SOLVED]

Game development with Board Game Arena Studio
Post Reply
User avatar
Badguizmo
Posts: 76
Joined: 11 October 2020, 14:27

getNextPlayerTable and when to call it [SOLVED]

Post by Badguizmo »

Hello everyone.

I am facing a problem when calling "getNextPlayerTable" on a 2 players game.
I want to retreive the ID for both players.

During the "setupNewGame" function, right before "$this->activeNextPlayer();" I am doing this :

Code: Select all

/************ Start the game initialization *****/
$players_turn = $this->getNextPlayerTable(); 
$this->setGameStateInitialValue( "player1id", $players_turn["0"] );
$this->setGameStateInitialValue( "player2id", $players_turn["1"] );

$this->activeNextPlayer();
Unfortunately I get an error :
Unexpected error: Wrong formatted data from BGA gameserver 1 (method: createGame): JSON_ERROR_SYNTAX
Notice: Undefined offset: 1 in /var/tournoi/release/games/badguizmotestun/999999-9999/badguizmotestun.game.php on line 120
{"status":1,"data":true}
Unexpected error: Invalid player number for this game: 1
A few topics mention this function has to be called after initialization.
But can I know when exactly ?

I have checked some other code and the function is called at the same time, except that they don't call the next player, only the first player.

I hope my question is clear ;)

NB : I can do without knowing the 2nd player ID as retreiving the 1st is working :D
Last edited by Badguizmo on 15 March 2021, 22:49, edited 1 time in total.
Official BGA developper newb :oops:
User avatar
Tisaac
Posts: 2743
Joined: 26 August 2014, 21:28

Re: getNextPlayerTable and when to call it

Post by Tisaac »

Badguizmo wrote: 14 March 2021, 00:42 Hello everyone.

I am facing a problem when calling "getNextPlayerTable" on a 2 players game.
I want to retreive the ID for both players.

During the "setupNewGame" function, right before "$this->activeNextPlayer();" I am doing this :

Code: Select all

/************ Start the game initialization *****/
$players_turn = $this->getNextPlayerTable(); 
$this->setGameStateInitialValue( "player1id", $players_turn["0"] );
$this->setGameStateInitialValue( "player2id", $players_turn["1"] );

$this->activeNextPlayer();
Unfortunately I get an error :
Unexpected error: Wrong formatted data from BGA gameserver 1 (method: createGame): JSON_ERROR_SYNTAX
Notice: Undefined offset: 1 in /var/tournoi/release/games/badguizmotestun/999999-9999/badguizmotestun.game.php on line 120
{"status":1,"data":true}
Unexpected error: Invalid player number for this game: 1
A few topics mention this function has to be called after initialization.
But can I know when exactly ?

I have checked some other code and the function is called at the same time, except that they don't call the next player, only the first player.

I hope my question is clear ;)

NB : I can do without knowing the 2nd player ID as retreiving the 1st is working :D
I think you misunderstood what nextPlayerTable is actually. It's an associative array where a player ID is associated with the next player ID.
So unless your player ID is 1, then indeed it's not defined...
The index 0 is defined because it's holding the first player, so what you should do is probably something like :

Code: Select all

$this->setGameStateInitialValue( "player1id", $players_turn[0] );
$this->setGameStateInitialValue( "player2id", $players_turn[$players_turn[0]] );
User avatar
Badguizmo
Posts: 76
Joined: 11 October 2020, 14:27

Re: getNextPlayerTable and when to call it

Post by Badguizmo »

Hello Tisaac.

Indeed, you focused the right words : "associative array".

Wrong reading on my side ... :cry:

:oops: :oops: :oops:

Will try this ASAP.
Thank you !!
Official BGA developper newb :oops:
Post Reply

Return to “Developers”