"an unexpected error has occurred" when launching the game

Game development with Board Game Arena Studio
Post Reply
tet2brick
Posts: 11
Joined: 06 May 2022, 11:04

"an unexpected error has occurred" when launching the game

Post by tet2brick »

Hi Everyone,

Some users of the game Tiwanaku in alpha get error messages when trying to launch the game :

Code: Select all

Sorry, an unexpected error has occurred...

Error while processing database request (reference: GS2 26/12 15:48:10)

>> Get me out of here <<
I can't reproduce this error, whether in dev or in alpha

Does someone have an idea ?

Thank you :D
User avatar
BrianLovesMarvel
Posts: 41
Joined: 20 March 2020, 23:58

Re: "an unexpected error has occurred" when launching the game

Post by BrianLovesMarvel »

One thing for me that's challenging is understanding what is happening in the BGA Studio framework outside of my code.

I'm basically writing plug-ins and call-backs, but the main program is BGA Studio, and despite the pretty good doc I don't fully understand what happens exactly when in the flow. I know that early in the setup, the database is created. Then the tables I define in dbmodel.sql are created. After that I can use dbQuery and perform inserts to set up the data for the game. But exactly when I should do what is still a little murky to me.

Recently I saw a similar database error when I tried to add a deck to my game. I found I had to add the deck in the constructor, and I had to do the initialization of the deck in setupNewGame. I couldn't do both in the constructor, and I couldn't do both in setupNewGame. I had to split the code. I think the database and tables are created after the constructor and before setupNewGame. I'm not sure how I can verify that though.

I also follow the posted advice of keeping the template setupNewGame as much as possible, and just calling an extra function initTables from setupNewGame to do the table setup and other initialization. This gives better debugging messages. An error in setupNewGame itself throws a message that isn't very descriptive.

Maybe you are running into a timing issue that is related to when some part of your code is executing. Perhaps you have something in the constructor that belongs in setupNewGame/initTables instead.

Since it only happens with some users, perhaps they are doing something different: choosing a different game option? number of players? preferred language?

Do the same people always get the same error, or is it only sometimes for those people?

Please let us know what you find out on this. Happy hunting!

Brian
User avatar
SwHawk
Posts: 133
Joined: 23 August 2015, 16:45

Re: "an unexpected error has occurred" when launching the game

Post by SwHawk »

BrianLovesMarvel wrote: 31 December 2022, 14:26 I don't fully understand what happens exactly when in the flow. I know that early in the setup, the database is created. Then the tables I define in dbmodel.sql are created. After that I can use dbQuery and perform inserts to set up the data for the game. But exactly when I should do what is still a little murky to me.

[...]

I found I had to add the deck in the constructor, and I had to do the initialization of the deck in setupNewGame. I couldn't do both in the constructor, and I couldn't do both in setupNewGame. I had to split the code. I think the database and tables are created after the constructor and before setupNewGame.
The game constructor will be called each and every time the game class will be instantiated, so pretty much whenever a player will make a request to the back end. On the other hand, setupNewGame is only called once, when the table is created. So it stands to reason that you initialize the deck during setupNewGame, because cards need to be created once. But the deck component, which you will use to access the cards will be needed for most of the requests...
User avatar
BrianLovesMarvel
Posts: 41
Joined: 20 March 2020, 23:58

Re: "an unexpected error has occurred" when launching the game

Post by BrianLovesMarvel »

The game constructor will be called each and every time the game class will be instantiated, so pretty much whenever a player will make a request to the back end.
Thank you!

I have a lot of experience with php, yet I've been incorrectly imagining that with BGA, game.php is running constantly on the server.

Something is running constantly, to bug players that aren't responding, but from your comment I now understand that game.php is only active from the moment a player interacts with the game browser javascript and a request is sent to the server. game.php runs, constructs the game object, loads the game state, interprets the request, notifies the players, changes the stored game state, and then stops. Is that right?

Much appreciated! Brian
User avatar
SwHawk
Posts: 133
Joined: 23 August 2015, 16:45

Re: "an unexpected error has occurred" when launching the game

Post by SwHawk »

BrianLovesMarvel wrote: 02 January 2023, 18:49 Something is running constantly, to bug players that aren't responding
The websocket server is responsible for that, but from what I've seen, it is decoupled from the game logic. Might be a Node.js server, or any other websocket server implementation...
BrianLovesMarvel wrote: 02 January 2023, 18:49 now understand that game.php is only active from the moment a player interacts with the game browser javascript and a request is sent to the server. game.php runs, constructs the game object, loads the game state, interprets the request, notifies the players, changes the stored game state, and then stops. Is that right?
Pretty much, although an action doesn't necessarily changes the game state (i.e. when in a multipleactiveplayer state, the player becomes inactive unless it's the last player that was active, which is when the gamestate transition happens). Also, this is rolled back should the PHP code throw an exception in the process, and that exception is notified to the javascript client.
Post Reply

Return to “Developers”