BGA bug? gameSetup state in JavaScript

Game development with Board Game Arena Studio
Post Reply
User avatar
quietmint
Posts: 299
Joined: 31 July 2017, 00:28

BGA bug? gameSetup state in JavaScript

Post 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 
User avatar
Brainchild
Posts: 71
Joined: 31 January 2014, 19:42

Re: BGA bug? gameSetup state in JavaScript

Post by Brainchild »

Looking at your state machine, shouldn't "gameSetup" and "powerSetup" always come first at the start of a game?
Last edited by Brainchild on 05 July 2020, 10:42, edited 1 time in total.
User avatar
quietmint
Posts: 299
Joined: 31 July 2017, 00:28

Re: BGA bug? gameSetup state in JavaScript

Post by quietmint »

Yes, so why doesn't JavaScript UI always go there? Why does it only go there on some games?
User avatar
Brainchild
Posts: 71
Joined: 31 January 2014, 19:42

Re: BGA bug? gameSetup state in JavaScript

Post 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.
User avatar
quietmint
Posts: 299
Joined: 31 July 2017, 00:28

Re: BGA bug? gameSetup state in JavaScript

Post 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?
User avatar
Brainchild
Posts: 71
Joined: 31 January 2014, 19:42

Re: BGA bug? gameSetup state in JavaScript

Post 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.
User avatar
sourisdudesert
Administrateur
Posts: 4630
Joined: 23 January 2010, 22:02

Re: BGA bug? gameSetup state in JavaScript

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

Return to “Developers”