Page 1 of 1

getNextPlayerTable and when to call it [SOLVED]

Posted: 14 March 2021, 00:42
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

Re: getNextPlayerTable and when to call it

Posted: 15 March 2021, 00:09
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]] );

Re: getNextPlayerTable and when to call it

Posted: 15 March 2021, 22:48
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 !!