Page 1 of 1

Initializing Stats

Posted: 18 January 2024, 15:15
by tony58uk
Hi all,

I'm working on my first project and having problems with initialising the Stats. I'm getting this error

Unexpected error: Wrong formatted data from gameserver 1 (method: createGame): JSON_ERROR_SYNTAX
Fatal error: Uncaught Error: Call to undefined function startsWith()

I'm using the code below which is meant to work out of the box from the wiki
https://en.doc.boardgamearena.com/Creat ... alkthrough

Any one have an idea? I must be missing something, or maybe there is a better example somewhere.

Thanks

Code: Select all

 public function initStats()
 {
     // INIT GAME STATISTIC
     $all_stats = $this->getStatTypes();
     $player_stats = $all_stats['player'];
     // auto-initialize all stats that starts with game_
     // we need a prefix because there is some other system stuff
     foreach ($player_stats as $key => $value) {
         if (startsWith($key, 'game_')) {
             $this->initStat('player', $key, 0);
         }
         if ($key === 'turns_number') {
             $this->initStat('player', $key, 0);
         }
     }
     $table_stats = $all_stats['table'];
     foreach ($table_stats as $key => $value) {
         if (startsWith($key, 'game_')) {
             $this->initStat('table', $key, 0);
         }
         if ($key === 'turns_number') {
             $this->initStat('table', $key, 0);
         }
     }
 }


Re: Initializing Stats

Posted: 18 January 2024, 15:41
by Jonathan2004
Your stats.json file is empty

more infos here : https://en.doc.boardgamearena.com/Game_ ... stats.json

Re: Initializing Stats

Posted: 18 January 2024, 19:06
by tony58uk
Jonathan2004 wrote: 18 January 2024, 15:41 Your stats.json file is empty

more infos here : https://en.doc.boardgamearena.com/Game_ ... stats.json
Oh thanks, I'll have a look at that :)

Re: Initializing Stats

Posted: 18 January 2024, 19:22
by tony58uk
Hi there,

I added some dummy Stats to the JSON file but still getting the same error.

Here is the full output.

Unexpected error: Wrong formatted data from gameserver 1 (method: createGame): JSON_ERROR_SYNTAX
Fatal error: Uncaught Error: Call to undefined function startsWith() in /var/tournoi/release/games/ominoestony/999999-9999/ominoestony.game.php:128 Stack trace: #0 /var/tournoi/release/games/ominoestony/999999-9999/ominoestony.game.php(105): OminoesTony->initStats() #1 /var/tournoi/release/games/ominoestony/999999-9999/ominoestony.game.php(92): OminoesTony->initTables() #2 /var/tournoi/release/tournoi-240116-1000-gs/www/game/module/table/table.game.php(361): OminoesTony->setupNewGame() #3 /var/tournoi/release/tournoi-240116-1000-gs/www/game/module/gameserver/gameserver.game.php(171): Table->setupNewGameTable() #4 /var/tournoi/release/tournoi-240116-1000-gs/www/action/gameserver/gameserver.action.php(65): Gameserver->createGame() #5 /var/tournoi/release/tournoi-240116-1000-gs/www/action/gameserver/gameserver.action.php(73): action_gameserver->callClusterJob() #6 /var/tournoi/release/tournoi-240116-1000-gs/www/include/webActionCore.inc.php(189): action_gameserver->createGame() #7 /var/tournoi/release/tournoi-240116-1000-gs/ in /var/tournoi/release/games/ominoestony/999999-9999/ominoestony.game.php on line 128
(reference: GS0 18/01 19:19:20)

Re: Initializing Stats

Posted: 19 January 2024, 01:14
by Victoria_La
Then your stats file is still wrong

Re: Initializing Stats

Posted: 19 January 2024, 10:05
by RicardoRix
Just gonna go with the obvious:
where does 'startsWith' come from?
Fatal error: Uncaught Error: Call to undefined function startsWith()
do you mean 'str_starts_with' ?

Re: Initializing Stats

Posted: 23 January 2024, 05:13
by Victoria_La
RicardoRix wrote: 19 January 2024, 10:05 Just gonna go with the obvious:
where does 'startsWith' come from?
Fatal error: Uncaught Error: Call to undefined function startsWith()
do you mean 'str_starts_with' ?
Oh wow I put this code in cookbook and nobody run it I guess, I usually have global definied for this function since php did not have one.
I guess can add php 8 one str_starts_with

Re: Initializing Stats

Posted: 26 January 2024, 21:33
by tony58uk
Victoria_La wrote: 23 January 2024, 05:13
RicardoRix wrote: 19 January 2024, 10:05 Just gonna go with the obvious:
where does 'startsWith' come from?
Fatal error: Uncaught Error: Call to undefined function startsWith()
do you mean 'str_starts_with' ?
Oh wow I put this code in cookbook and nobody run it I guess, I usually have global definied for this function since php did not have one.
I guess can add php 8 one str_starts_with

Thanks Victoria - I'll give this a try tomorrow. I had a feeling the function was undefined in some way but don't know too much PHP at this stage.