Page 1 of 1

Database Transactions and 'game' actions

Posted: 14 April 2020, 17:38
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?

Re: Database Transactions and 'game' actions

Posted: 14 April 2020, 17:50
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

Re: Database Transactions and 'game' actions

Posted: 14 April 2020, 18:37
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.