Database Transactions and 'game' actions
Posted: 14 April 2020, 17:38
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:
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:
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?
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);
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;
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?