Quote:
Originally Posted by Carnage-
well, a problem i had with a game i wrote was that i was comparing the money to a value loaded when the script started part way thru the scripts execution you then update based on the value in the database which might have changed since you loaded it.
If you change your db query to update to a set value it will reduce the problem.
$test->db->query("update test_user set money=money-'{$Land_Cost}' where uid='{$test->user['uid']}'");
should be
$newmoney = $test->user['money'] - $Land_Cost;
$test->db->query("update test_user set money=$newmoney where uid='{$test->user['uid']}'");
a second way which may not be possible depending on your setup is to change your database engine to innodb and use row locking to prevent the data being changed while you are modifying it.
|
Carnage, your $newmoney variable seems to have done the trick. I tested it over 20 times so far and it hasn't doubled the cost at all. I'll let you know if I notice a problem with it later on. Thank you.
Opserty, thanks for the recommendation. Even though my goal is accomplished with my current setup, I'll definitely change it over to what you posted. Thanks.