Page 1 of 1

BGA bug? gameSetup state in JavaScript

Posted: 04 July 2020, 18:49
by quietmint
It seems the BGA framework has a race condition bug about game states. Sometimes, the JavaScript UI receives onEnteringState() call for "gameSetup" at the start of the game, but sometimes it does not. Why is the behavior inconsistent?

My states.inc.php file looks something like this:

Code: Select all

  ST_BGA_GAME_SETUP => [
    'name' => 'gameSetup',
    'description' => '',
    'type' => 'manager',
    'action' => 'stGameSetup',
    'transitions' => [
      '' => ST_POWERS_SETUP,
    ],
  ],

  ST_POWERS_SETUP => [
    'name' => 'powersSetup',
    'description' => '',
    'type' => 'game',
    'action' => 'stPowersSetup',
    'transitions' => [
      'placeWorker' => ST_NEXT_PLAYER_PLACE_WORKER,
      'offer' => ST_BUILD_OFFER,
      'chooseFirstPlayer' => ST_CHOOSE_FIRST_PLAYER
    ],
  ],

  ST_BUILD_OFFER => [
    'name' => 'buildOffer',
    'type' => 'activeplayer',
    ...
Usually, the first state we get in the JavaScript UI is "buildOffer".

But here is a production example where "gameSetup" and "powerSetup" were sent to the UI first!
https://boardgamearena.com/archive/repl ... 161;#debug

Code: Select all

Entering state: gameSetup {id: "1", active_player: "6870632", args: null, reflexion: {…}, updateGameProgression: 0, …}
Leaving state: gameSetup
Entering state: powersSetup {id: 10, active_player: "6870632", args: null, type: "game", reflexion: {…}, …}
Leaving state: powersSetup
Entering state: buildOffer 

Re: BGA bug? gameSetup state in JavaScript

Posted: 05 July 2020, 08:32
by Brainchild
Looking at your state machine, shouldn't "gameSetup" and "powerSetup" always come first at the start of a game?

Re: BGA bug? gameSetup state in JavaScript

Posted: 05 July 2020, 09:36
by quietmint
Yes, so why doesn't JavaScript UI always go there? Why does it only go there on some games?

Re: BGA bug? gameSetup state in JavaScript

Posted: 05 July 2020, 10:54
by Brainchild
I think gameSetup state is happening while the loading screen is still up, so you shouldn't put any code there. If you want to run Javascript code as part of game setup you should put it in setup().

And when a player refreshes the page (F5) they will only get the onEnteringState for the current state anyway, so I don't think it makes sense to put code in powersSetup either.

Re: BGA bug? gameSetup state in JavaScript

Posted: 05 July 2020, 12:30
by quietmint
I understand. In fact, onEnteringState() for "gameSetup" was quite unexpected and it caused my bug. My point is: When starting a game, the BGA framework behavior is inconsistent. For a new game (not talking about refresh the page F5 and rejoin the game late) I should either always or never get onEnteringState() for "gameSetup". Currently the behavior seems random. Most games never call onEnteringState() for "gameSetup", but some games do. I am guessing it depends on the time taken on the server side for this state?

Re: BGA bug? gameSetup state in JavaScript

Posted: 05 July 2020, 13:32
by Brainchild
Yes the timing is probably related to how quickly the game loading happens. Perhaps the server is sending the event before the client has registered the onEnteringState callback.

Re: BGA bug? gameSetup state in JavaScript

Posted: 06 July 2020, 08:36
by sourisdudesert
Hi.

You are right, this is related to loading time.

However it should not have any consequences: on onEnteringState it is expected that you are doing a different treatment for game states, so if it is called on gameSetup, it is expected to do nothing.