Database Transactions and 'game' actions

Game development with Board Game Arena Studio
Post Reply
whites11
Posts: 5
Joined: 10 April 2020, 14:47

Database Transactions and 'game' actions

Post by whites11 »

Hello folks.

I have a simple sequence of actions in my game:

attack -> nextPlayer

attack is an 'activeplayer' action, while nextPlayer is a 'game' action.

I need to pass data between the two, so I added a new column in the players table and run this query in the 'attack' action:

Code: Select all

$sql = "UPDATE player SET player_double_turn=1 WHERE player_id='$victim'";
self::DbQuery($sql);
If I read the data from within the same function, I get the correct value.
I expected the database transaction to be committed as soon as my 'attack' function returns, but apparently that's not the case.

In fact, when I try to read the data from nextPlayer's 'action' function, like this:

Code: Select all

$result = self::getObjectFromDB( "SELECT player_double_turn FROM player WHERE player_id='$player_id'" );
var_dump($result);die;
The value is still the old one.

Only after the nextPlayer action is completed as well I get the right value in the database (checked with phpMyAdmin).

How is the intended way of passing data between one action to the other in this scenario?
User avatar
A-dam
Posts: 107
Joined: 28 September 2013, 18:15

Re: Database Transactions and 'game' actions

Post by A-dam »

Code: Select all

$result = self::getObjectFromDB( "SELECT player_double_turn FROM player WHERE player_id='$player_id'" );
var_dump($result);die;

If you are really testing with exactly this code, than of course, die(); will cancel your db updates

About how to "passing" data it depends widely on what are you trying to achieve. From your post it is not clear. Of course storing data to DB is one of the option, and if that data are ever needed when user hit F5 than they must be there. Another option might be to move part of the logic from nextPlayer, to action function.
You can also use globals (http://en.doc.boardgamearena.com/Main_g ... se_globals) but this is also database way
whites11
Posts: 5
Joined: 10 April 2020, 14:47

Re: Database Transactions and 'game' actions

Post by whites11 »

The die; call Is of course there for troubleshooting reasons.
But I would expect to read the right data from the database in the nextPlayer function call.
Anyhow, I skipped using the database completely changing my strategy and it works now.
Post Reply

Return to “Developers”