The problem is likely a synchronization issue. Nevermind what I wrote about references. Will post again if I fix it. Sorry about that! Thanks to the poster for replying!
*EDIT*
I had to play with a lot of variables to find the solution to this problem.
Let's say that, in one function thread, a C# server loads a UInt value from BigDB, changes that value, and then attempts to save the changes in a new separate BigDB load statement.
Assuming the value of Cash is 9,000,000 in the databaseobject:
- Code: Select all
PlayerIO.BigDB.Load("Players", Username, delegate(DatabaseObject result) {
// ...
Cash = result.GetUInt("Cash"); // Console.WriteLine reports Cash as 9,000,000
// ...
}
Cash += 100,000; // Console.WriteLine reports Cash as 9,100,000
PlayerIO.BigDB.Load("Players", Username, delegate(DatabaseObject result) {
// The moment this second load statement occurs, the value of Cash gets reset back to 9,000,000.
// Console.WriteLine reports Cash as 9,000,000
// ...
result.Set("Cash", Cash); // Sets Cash to its current value of 9,000,000 instead of the correct value of 9,100,000.
// ...
);
I figured that, somehow the second BigDB load statement caused the value of Cash to reset itself, even though I never loaded that value into the Cash variable in the second BigDB statement. So the value must be getting reset due to some reference crap.
The solution is to create a new UInt variable called NewCash, and to make sure that NewCash never gets passed the reference to Cash. Simply using "NewCash = Cash;" will not work, because it passes the reference which BigDB then alters upon the second BigDB load statement. Here's how I made it work:
- Code: Select all
uint NewCash;
NewCash = Cash + 10; // This ensures that a new value MUST be passed into NewCash, so that
// the value of NewCash and Cash are not equal, and the reference is not passed.
NewCash -= 10; // This resets the value of NewCash to the value of Cash, without passing a reference.
NewCash += Cost; // This adds the amount desired. Cost equals 100,000 in my example.
result.Set("Cash", NewCash); // This correctly saves the new value 9,100,000 to BigDB.