Unexpected error: Invalid player number for this game: 1

Game development with Board Game Arena Studio
Lone Boardgamer
Posts: 19
Joined: 16 September 2020, 21:49

Unexpected error: Invalid player number for this game: 1

Post by Lone Boardgamer »

I'm trying to start the 2 player game by clicking Express Start button. At first it displays 2 players (player0 and player1), which is correct, but suddenly stops loading with "Unexpected error: Invalid player number for this game: 1" message. And indeed on Accept/Refuse page only player0 is present.

I read a few topics regarding this error, but not much of them and I seem to have a different issue. This is my first game, so I'm not even sure where to start. I added var_dump() to the beginning of setupNewGame() function, but seems like this issue happens earlier. Full error message is:
Unexpected error: Wrong formatted data from BGA gameserver 1 (method: createGame): JSON_ERROR_SYNTAX
Notice: Undefined variable: actplayer in /var/tournoi/release/games/blitzkrieg/999999-9999/states.inc.php on line 12

Notice: Undefined variable: you in /var/tournoi/release/games/blitzkrieg/999999-9999/states.inc.php on line 13
{"status":"0","error":"BGA service error (1.studio.boardgamearena.com 24\/06 10:12:42)","expected":0,"code":100}
Unexpected error: Invalid player number for this game: 1
User avatar
Tisaac
Posts: 2736
Joined: 26 August 2014, 21:28

Re: Unexpected error: Invalid player number for this game: 1

Post by Tisaac »

You are using " instead of ' in your states.php file
Lone Boardgamer
Posts: 19
Joined: 16 September 2020, 21:49

Re: Unexpected error: Invalid player number for this game: 1

Post by Lone Boardgamer »

Tisaac wrote: 24 June 2021, 09:45 You are using " instead of ' in your states.php file
Yes, this fixed "Undefined variable: actplayer/you" part. What a weird error, I would've NEVER guessed that quotes are the reason! Thank you.

Still have an issue with player number. The new error message is:
Unexpected error: Propagating error from GS 1 (method: createGame): BGA service error (1.studio.boardgamearena.com 24/06 10:50:56)
Unexpected error: Invalid player number for this game: 1
Lone Boardgamer
Posts: 19
Joined: 16 September 2020, 21:49

Re: Unexpected error: Invalid player number for this game: 1

Post by Lone Boardgamer »

Error pops when startgame.html is called. Here's a stack, if it helps:
#0 /var/tournoi/release/tournoi-210621-0932/www/action/table/table.action.php(119): Tablemanager->startGame('280128')#1 /var/tournoi/release/tournoi-210621-0932/www/include/webActionCore.inc.php(189): action_table->startgame()#2 /var/tournoi/release/tournoi-210621-0932/www/index.php(259): launchWebAction('table', 'action_table', 'startgame', false, false, NULL, true, false)#3 {main}
User avatar
robinzig
Posts: 459
Joined: 11 February 2021, 18:23

Re: Unexpected error: Invalid player number for this game: 1

Post by robinzig »

Lone Boardgamer wrote: 24 June 2021, 09:51
Tisaac wrote: 24 June 2021, 09:45 You are using " instead of ' in your states.php file
Yes, this fixed "Undefined variable: actplayer/you" part. What a weird error, I would've NEVER guessed that quotes are the reason! Thank you.
I guess you're not familiar with PHP - there is a difference between using single quotes and double quotes for strings. Double quotes automatically interpolate variables, so anything inside a double-quoted string of the form $sometext or ${sometext} is treated as you wanting to substitute the value of the variable called $sometext. Unfortunately BGA's own interpolation system uses ${variable} to interpolate values from args, and these conflict - so you must use single quotes when using that (in notification strings as well as state descriptions). Single quotes tell PHP you just want the literal raw string inside, and the BGA framework then replaces things like ${actplayer} with the correct values.

This is actually in the docs, although I just checked and it's only mentioned in the context of notification strings:
You can use arguments in your notification_log strings, that refers to values defines in the "notification_args" argument (see below). Note: Make sure you only use single quotes ('), otherwise PHP will try to interpolate the variable and will ignore the values in the args array.
User avatar
robinzig
Posts: 459
Joined: 11 February 2021, 18:23

Re: Unexpected error: Invalid player number for this game: 1

Post by robinzig »

I've no idea about the "invalid player number" error, but given that the game starts with 2 players and then shortly after seems to think there's only 1 - are you doing something weird in setupNewGame that might accidentally remove a player from the players array, or remove a row from the players table?
User avatar
thoun
Posts: 1620
Joined: 10 December 2020, 22:25

Re: Unexpected error: Invalid player number for this game: 1

Post by thoun »

I have this error sometimes, but can't remember the cause. Usually I rollback my changes until it works then reintroduce changes until I catch the culprit line
Lone Boardgamer
Posts: 19
Joined: 16 September 2020, 21:49

Re: Unexpected error: Invalid player number for this game: 1

Post by Lone Boardgamer »

robinzig wrote: 24 June 2021, 10:27 I guess you're not familiar with PHP - there is a difference between using single quotes and double quotes for strings. Double quotes automatically interpolate variables, so anything inside a double-quoted string of the form $sometext or ${sometext} is treated as you wanting to substitute the value of the variable called $sometext. Unfortunately BGA's own interpolation system uses ${variable} to interpolate values from args, and these conflict - so you must use single quotes when using that (in notification strings as well as state descriptions). Single quotes tell PHP you just want the literal raw string inside, and the BGA framework then replaces things like ${actplayer} with the correct values.
I'm quite familiar with PHP and of course I understand the difference between single and double quotes. What confused me is that only in this particular case single quotes are required. Easy to miss.
Lone Boardgamer
Posts: 19
Joined: 16 September 2020, 21:49

Re: Unexpected error: Invalid player number for this game: 1

Post by Lone Boardgamer »

robinzig wrote: 24 June 2021, 10:31 I've no idea about the "invalid player number" error, but given that the game starts with 2 players and then shortly after seems to think there's only 1 - are you doing something weird in setupNewGame that might accidentally remove a player from the players array, or remove a row from the players table?
As I previously mentioned, I've tried to put var_dump() to the beginning of setupNewGame() function and it is not even fired. I even removed everything from this function except the basic stuff - same error. So definitely problem happens BEFORE this function is called.

As for "player" table, it is not even created, because the database itself is not created for this game. It was working before, so definitely I did something wrong.
Last edited by Lone Boardgamer on 24 June 2021, 11:00, edited 2 times in total.
Lone Boardgamer
Posts: 19
Joined: 16 September 2020, 21:49

Re: Unexpected error: Invalid player number for this game: 1

Post by Lone Boardgamer »

thoun wrote: 24 June 2021, 10:34 I have this error sometimes, but can't remember the cause. Usually I rollback my changes until it works then reintroduce changes until I catch the culprit line
I've made too much changes, basically built the complete game starting routine, so I can't go back.
Post Reply

Return to “Developers”