Reversi tutorial : JSON_ERROR_SYNTAX

Game development with Board Game Arena Studio
Post Reply
User avatar
JulienHrn
Posts: 4
Joined: 24 March 2020, 09:10

Reversi tutorial : JSON_ERROR_SYNTAX

Post by JulienHrn »

Hi to all developers,

I am following the reversi tutorial steps, currently in "Setup the initial game position" section, and I'm facing this error :

Code: Select all

Unexpected error: Wrong formatted data from BGA gameserver 1 (method: createGame): JSON_ERROR_SYNTAX
Notice: Undefined offset: 1 in /var/tournoi/release/games/reversijhtuto/999999-9999/reversijhtuto.game.php on line 89
{"status":1,"data":true}


Here is my php code (totally copied from the tutorial without any modification) :

Code: Select all

// Init the board
        $sql = "INSERT INTO board (board_x,board_y,board_player) VALUES ";
        $sql_values = array();
        list( $blackplayer_id, $whiteplayer_id ) = array_keys( $players );
        for( $x=1; $x<=8; $x++ )
        {
            for( $y=1; $y<=8; $y++ )
            {
                $token_value = "NULL";
                if( ($x==4 && $y==4) || ($x==5 && $y==5) )  // Initial positions of white player
                    $token_value = "'$whiteplayer_id'";
                else if( ($x==4 && $y==5) || ($x==5 && $y==4) )  // Initial positions of black player
                    $token_value = "'$blackplayer_id'";
                    
                $sql_values[] = "('$x','$y',$token_value)";
            }
        }
        $sql .= implode( $sql_values, ',' );
        self::DbQuery( $sql );
        
        
        // Active first player
        self::activeNextPlayer();  
(line 89 as mentioned in the error log is the one starting with "list( $blackplayer_id)

Where did I miss something ?

Thank you


EDIT : I only forgot to clic the "+" button to add a second player ! Now the game starts.
But it remains one problem : All four tokens are white !
Kohan01
Posts: 2
Joined: 10 April 2020, 10:16

Re: Reversi tutorial : JSON_ERROR_SYNTAX

Post by Kohan01 »

Hi JulienHrn,
I am doing the same tutorial.
I commented on the following lines of code in the "<projectName>.game.php" file:

To show the black tokens:

Code: Select all

//self::reattributeColorsBasedOnPreferences( $players, $gameinfos['player_colors'] ); 
For the problem of the extra player:

Code: Select all

// Activate first player (which is in general a good idea :) )
// $this->activeNextPlayer();
And I modify this line:

Code: Select all

$default_colors = array( "ffffff", "000000" );
in

Code: Select all

$default_colors = array( "000000", "ffffff" );
Kohan
User avatar
JulienHrn
Posts: 4
Joined: 24 March 2020, 09:10

Re: Reversi tutorial : JSON_ERROR_SYNTAX

Post by JulienHrn »

Thanks a lot !

This works fine now ! :)
Kohan01
Posts: 2
Joined: 10 April 2020, 10:16

Re: Reversi tutorial : JSON_ERROR_SYNTAX

Post by Kohan01 »

I took a few successive steps and I'm facing the same error:

Code: Select all

Unexpected error: Wrong formatted data from BGA gameserver 1 (method: createGame): JSON_ERROR_SYNTAX
Notice: Undefined offset: 1 in /var/tournoi/release/games/reversijhtuto/999999-9999/reversijhtuto.game.php on line 89
{"status":1,"data":true}
Caused by the JSON format of the "possibleMoves" of the "updatePossibleMoves" method; requires that the coordinates are the keys an array.
The matrix must be like this:

Code: Select all

$possibleMovesCoords = array(
	x1 => array(
		y1 => "",
		y2 => ""
	), x2 => array(
		y1 => ""
	)
);
I hope I was clear.

Kohan
Post Reply

Return to “Developers”