Initializing Stats

Game development with Board Game Arena Studio
Post Reply
tony58uk
Posts: 15
Joined: 23 March 2023, 20:09

Initializing Stats

Post 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);
         }
     }
 }

User avatar
Jonathan2004
Posts: 46
Joined: 21 April 2020, 19:06

Re: Initializing Stats

Post by Jonathan2004 »

Your stats.json file is empty

more infos here : https://en.doc.boardgamearena.com/Game_ ... stats.json
tony58uk
Posts: 15
Joined: 23 March 2023, 20:09

Re: Initializing Stats

Post 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 :)
tony58uk
Posts: 15
Joined: 23 March 2023, 20:09

Re: Initializing Stats

Post 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)
User avatar
Victoria_La
Posts: 665
Joined: 28 December 2015, 20:55

Re: Initializing Stats

Post by Victoria_La »

Then your stats file is still wrong
User avatar
RicardoRix
Posts: 2548
Joined: 29 April 2012, 23:43

Re: Initializing Stats

Post 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' ?
User avatar
Victoria_La
Posts: 665
Joined: 28 December 2015, 20:55

Re: Initializing Stats

Post 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
tony58uk
Posts: 15
Joined: 23 March 2023, 20:09

Re: Initializing Stats

Post 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.
Post Reply

Return to “Developers”