Game init crash on 3-4 players

Game development with Board Game Arena Studio
Post Reply
User avatar
galadae
Posts: 3
Joined: 24 July 2020, 13:06

Game init crash on 3-4 players

Post by galadae »

Hi!

I'm developing "Christmas Tree", and when I express start my game in 2 players mode everithing is fine.
However if I start with 3-4 players it can't pass the loading screen.

I got error message in console:
Uncaught SyntaxError: Unexpected token ',' christmastree?table=431344:2224

This line contains:

Code: Select all

gameui.completesetup( "christmastree", "christmastree", 431344, 2372082, /*archivemask_begin*/"eb6df31356e5e91d858903c9476b66f8"/*archivemask_end*/, "d1f957a7a45cbd326e12933799a6ee13","socketio", , {"2372082":{"user_id":"2372082","status":"offline","device":"desktop","language":"en","player_name":"galadae0","grade":"3","rank":1300,"karma":"75","country":"XX","city":null,"avatar":"000000","tutorial_seen":"FFFFFFFFFFFFFFFFFFFFFFFFFFDFCFFF","gender":null,"is_premium":"1","is_beginner":"0","languages":{"en":{"id":"en","level":"0"}},"country_infos":{"flag":249,"name":"Unknown","cur":"EUR","code":"XX","flag_x":384,"flag_y":99}},"2372083":{"user_id":"2372083","status":"offline","device":"desktop","language":"en","player_name":"galadae1","grade":"3","rank":1301,"karma":"75","country":"XX","city":null,"avatar":"000000","tutorial_seen":"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF","gender":null,"is_premium":"1","is_beginner":"0","languages":{"en":{"id":"en","level":"0"}},"country_infos":{"flag":249,"name":"Unknown","cur":"EUR","code":"XX","flag_x":384,"flag_y":99}},"2372084":{"user_id":"2372084","status":"offline","device":"desktop","language":"en","player_name":"galadae2","grade":"3","rank":1300,"karma":"75","country":"XX","city":null,"avatar":"000000","tutorial_seen":"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF","gender":null,"is_premium":"1","is_beginner":"0","languages":{"en":{"id":"en","level":"0"}},"country_infos":{"flag":249,"name":"Unknown","cur":"EUR","code":"XX","flag_x":384,"flag_y":99}}}, "https://studio.boardgamearena.com:3000", "r" );
With 2 players the same line looks like this:

Code: Select all

gameui.completesetup( "christmastree", "christmastree", 431444, 2372082, /*archivemask_begin*/"eb6df31356e5e91d858903c9476b66f8"/*archivemask_end*/, "7177650e3cc34892896b46dace22e54b","socketio", {"current_player_data":{"player_no":"1","player_id":"2372082","player_canal":"7177650e3cc34892896b46dace22e54b","player_name":"galadae0","player_avatar":"000000","player_color":"ff0000","player_score":"0","player_score_aux":"0","player_zombie":"0","player_ai":"0","player_eliminated":"0","player_next_notif_no":"1","player_enter_game":"1","player_over_time":"0","player_is_multiactive":"1","player_start_reflexion_time":"2022-12-23 12:55:33","player_remaining_reflexion_time":"180","player_beginner":null,"player_state":"1","decors":"[\"D09\",\"D12\",\"D17\",\"D35\",\"D44\",\"D49\",\"SZ03\",\"SZ09\"]","quests":"[\"0\", \"2\", \"10\", \"16\"]","board":"[\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\"]","available_places":"[true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true]"},"current_player_quests":["E01","E06","E26","E12"],"gamestate":{"id":"3","active_player":"0","args":{"2372082":{"player_no":"1","player_id":"2372082","player_canal":"7177650e3cc34892896b46dace22e54b","player_name":"galadae0","player_avatar":"000000","player_color":"ff0000","player_score":"0","player_score_aux":"0","player_zombie":"0","player_ai":"0","player_eliminated":"0","player_next_notif_no":"1","player_enter_game":"1","player_over_time":"0","player_is_multiactive":"1","player_start_reflexion_time":"2022-12-23 12:55:33","player_remaining_reflexion_time":"180","player_beginner":null,"player_state":"1","decors":"[\"D09\",\"D12\",\"D17\",\"D35\",\"D44\",\"D49\",\"SZ03\",\"SZ09\"]","quests":"[\"0\", \"2\", \"10\", \"16\"]","board":"[\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\"]","available_places":"[true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true]"},"2372083":{"player_no":"2","player_id":"2372083","player_canal":"68e9b27a5964daba992e7a7c97a056fe","player_name":"galadae1","player_avatar":"000000","player_color":"008000","player_score":"0","player_score_aux":"0","player_zombie":"0","player_ai":"0","player_eliminated":"0","player_next_notif_no":"1","player_enter_game":"0","player_over_time":"0","player_is_multiactive":"1","player_start_reflexion_time":"2022-12-23 12:55:33","player_remaining_reflexion_time":"180","player_beginner":null,"player_state":"1","decors":"[\"D01\",\"D04\",\"D27\",\"D46\",\"D52\",\"D54\",\"SZ06\",\"SZ15\"]","quests":"[\"1\", \"5\", \"7\", \"15\"]","board":"[\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\"]","available_places":"[true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true]"}},"reflexion":{"total":{"2372082":129,"2372083":129}},"multiactive":["2372082","2372083"],"updateGameProgression":0},"tablespeed":"1","game_result_neutralized":"0","neutralized_player_id":"0","players":{"2372082":{"color":"ff0000","color_back":null,"name":"galadae0","avatar":"000000","zombie":0,"eliminated":0,"is_ai":"0","beginner":false},"2372083":{"color":"008000","color_back":null,"name":"galadae1","avatar":"000000","zombie":0,"eliminated":0,"is_ai":"0","beginner":false}},"playerorder":["2372082",2372083],"gamestates":{"1":{"name":"gameSetup","description":"","type":"manager","action":"stGameSetup","transitions":{"":2}},"2":{"name":"makeHands","type":"game","description":"","action":"stMakeHands","transitions":{"startRound":3}},"3":{"name":"selectQuest","type":"multipleactiveplayer","description":"","descriptionmyturn":"","transitions":{"selectDecor":4},"possibleactions":["selectQuest"],"updateGameProgression":true,"args":"argSelectQuest"},"4":{"name":"selectDecor","type":"multipleactiveplayer","description":"","descriptionmyturn":"","transitions":{"passHands":5,"dropLasts":6},"possibleactions":["selectDecor"],"updateGameProgression":true,"args":"argSelectDecor"},"5":{"name":"passHands","type":"game","description":"","action":"stPassHands","transitions":{"nextTurn":4}},"6":{"name":"dropLasts","type":"game","description":"","action":"stDropLasts","transitions":{"addScores":7}},"7":{"name":"addScores","type":"game","description":"","action":"stAddScores","transitions":{"writeScores":8}},"8":{"name":"writeScores","type":"game","description":"","action":"stWriteScores","transitions":{"endGame":99,"nextRound":2},"args":"argWriteScores"},"99":{"name":"gameEnd","description":"End of game","type":"manager","action":"stGameEnd","args":"argGameEnd"}},"notifications":{"last_packet_id":"1","move_nbr":"1"}}, {"2372082":{"user_id":"2372082","status":"online","device":"desktop","language":"en","player_name":"galadae0","grade":"3","rank":1300,"karma":"75","country":"XX","city":null,"avatar":"000000","tutorial_seen":"FFFFFFFFFFFFFFFFFFFFFFFFFFDFCFFF","gender":null,"is_premium":"1","is_beginner":"0","languages":{"en":{"id":"en","level":"0"}},"country_infos":{"flag":249,"name":"Unknown","cur":"EUR","code":"XX","flag_x":384,"flag_y":99}},"2372083":{"user_id":"2372083","status":"offline","device":"desktop","language":"en","player_name":"galadae1","grade":"3","rank":1301,"karma":"75","country":"XX","city":null,"avatar":"000000","tutorial_seen":"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF","gender":null,"is_premium":"1","is_beginner":"0","languages":{"en":{"id":"en","level":"0"}},"country_infos":{"flag":249,"name":"Unknown","cur":"EUR","code":"XX","flag_x":384,"flag_y":99}}}, "https://studio.boardgamearena.com:3000", "r" );
What I see as difference is the game datas after socket io.

My problem with this is, when I push a var_dump die combo in my getAllDatas in game.php just before return everithing is fine, every data is correct, and looks like this:

Code: Select all

array(2) { ["current_player_data"]=> array(23) { ["player_no"]=> string(1) "3" ["player_id"]=> string(7) "2372082" ["player_canal"]=> string(32) "7decf03126a5a1f4ab0094ea88dd6bb0" ["player_name"]=> string(8) "galadae0" ["player_avatar"]=> string(6) "000000" ["player_color"]=> string(6) "0000ff" ["player_score"]=> string(1) "0" ["player_score_aux"]=> string(1) "0" ["player_zombie"]=> string(1) "0" ["player_ai"]=> string(1) "0" ["player_eliminated"]=> string(1) "0" ["player_next_notif_no"]=> string(1) "1" ["player_enter_game"]=> string(1) "1" ["player_over_time"]=> string(1) "0" ["player_is_multiactive"]=> string(1) "1" ["player_start_reflexion_time"]=> string(19) "2022-12-23 13:03:02" ["player_remaining_reflexion_time"]=> string(3) "180" ["player_beginner"]=> NULL ["player_state"]=> string(1) "1" ["decors"]=> string(49) "["D01","D05","D29","D32","D40","D46","D47","D52"]" ["quests"]=> string(22) "["6", "7", "12", "17"]" ["board"]=> string(64) "["","","","","","","","","","","","","","","","","","","","",""]" ["available_places"]=> string(106) "[true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true]" } ["current_player_quests"]=> array(4) { [0]=> string(3) "E11" [1]=> string(3) "E23" [2]=> string(3) "E28" [3]=> string(3) "E13" } }
Do you have any hint, what can be the problem, or how can I debug this?
Last edited by galadae on 23 December 2022, 13:59, edited 1 time in total.
User avatar
SwHawk
Posts: 133
Joined: 23 August 2015, 16:45

Re: Game init crash on 3-4 players

Post by SwHawk »

I'm surprised your arrays are cast to strings which might cause a problem, whichever number of players around the table...

Also you should enclose your code with code markup (icon with brackets and slash on the editing page) to make it more readable
User avatar
galadae
Posts: 3
Joined: 24 July 2020, 13:06

Re: Game init crash on 3-4 players

Post by galadae »

Ok, I changed it.

My arrays are json encoded, because mysql has JSON type field and with this cards in hand and players unique boards are just in one field.
To pass frontend I keep in json format and javascript can parse it back to array.
I found this stable way to handle data, and worked well with 2 players.

Or I missed what you wanted to point at.

Here is my getAllDatas function:

Code: Select all

protected function getAllDatas()
    {
        $result = [];

        $player = $this->getCurrentPlayer();

        $result['current_player_data'] = $this->formatPlayerData($player);
        $result['current_player_quests'] = QuestHelper::mapIdsToImage($this->getPlayerQuests($player));

        return $result;
    }
This is not casted by me, just players fields

Format just map my raw data to showable card classes, so nothing special
User avatar
SwHawk
Posts: 133
Joined: 23 August 2015, 16:45

Re: Game init crash on 3-4 players

Post by SwHawk »

That's your choice keeping those informations in JSON on the DB, but since you'll have to check everything on the PHP side when a player submits an action, you'll have to parse it on the PHP side as well... Are you sure you're building those JSON strings and getting them back correctly from the DB?
User avatar
RicardoRix
Posts: 2548
Joined: 29 April 2012, 23:43

Re: Game init crash on 3-4 players

Post by RicardoRix »

I think it's a case of inadvertent escape characters that are having a strange effect.
Most likely the use of the /* and */
like with:
/*archivemask_begin*/

try changing it to:
__archivemask_begin__

either that, or you're somehow corrupting the result array.
Last edited by RicardoRix on 23 December 2022, 14:36, edited 2 times in total.
User avatar
robinzig
Posts: 461
Joined: 11 February 2021, 18:23

Re: Game init crash on 3-4 players

Post by robinzig »

It looks like a framework issue, although doubtless there's still something in your code that's making the framework generate this invalid JS. (It looks like they're generating Javascript with PHP, wow.)

I don't know what's up but one thought I have: your `getAllDatas` is `protected`. I assumed any methods that the framework needs to call from outside your class need to be `public`. Have you tried changing that? I' m not confident but surely worth a try...
User avatar
galadae
Posts: 3
Joined: 24 July 2020, 13:06

Re: Game init crash on 3-4 players

Post by galadae »

Thank you for replies, here my answers.

GetAllData was made by environment when generated the project, and that was protected then. If I change it to public result is the same, and still works well with 2 players.

I will write to administrators, to check if it is a framework issue, thank you.

Data initialize well in database and can reenter the game, so I think background data is good, and I use same decode method everywhere, here an example

Code: Select all

    function getPlayerQuests($player): array
    {
        return json_decode($player['quests'], true);
    }
So when i want to access that decors I always get back my associative array, and I access this data only this way.
And my thoughts are if it would be the problem is should not work with 2 players as well.

This error not happens when players submits actions. After initialization no player can access the game, just in 2 player mode. I wrote handle classes and handle methods for every special work, to be sure no code is duplicated and if something is bugy I have to fix it on one place, so I not let places unfixed, but I double checked.

Two player mode is special, cause the is a third player, who have cards, but not playes just keep cards when players drafts.
This should not be a problem, or not in this way, cause third party player is only means when game is initialize, or after rounds, but looks like init works well, and players can't reach the after round state. Third player still inits in 3-4 players mode, just never used, so the problem is not missing data, or something like that.

And /*archivemask_begin*/ was not made by me, it is not part of my code it comes from framework, so I have no idea how could I change it, so I can't try this hint, sorry

Verry strange situtation :)
User avatar
RicardoRix
Posts: 2548
Joined: 29 April 2012, 23:43

Re: Game init crash on 3-4 players

Post by RicardoRix »

did you change the players[] in gameinfos and hit the update button?

you could try to change some of the data being passed in result[] to perhaps hunt down the particular data that causes a corruption.
take it all out, and slowly add it back in piece by piece. process of elimination.
Post Reply

Return to “Developers”