- Code: Select all
//Get waiting players in order of largest party
PlayerIO.BigDB.LoadRange("matchmaking", "partyCount", null, 18, 1, 100, delegate(DatabaseObject[] result) {
for(int i = 0; i <= result.Length - 1; i ++) {
//Attempt to place this person / party in an existing game
/* DEV NOTICE - ACTUAL SETUP ONLY PLACES FIRST ARRAY ELEMENT (FIRST FBUID) INTO GAME, SEE [0] BELOW */
string curFBUID = result[i].GetArray("facebookUIDs")[0].ToString();
Console.WriteLine("Attempting to place " + curFBUID + " in an existing game");
PlayerIO.BigDB.LoadRange("activeGames", "totalFreeSlots", null, 18, result[i].GetInt("partyCount"), 1, delegate(DatabaseObject[] resultEG) {
if(resultEG.Length > 0) {
//Found existing game with free slot(s), moving this player / party to that game
Console.WriteLine("Found existing game with suitable slot(s), moving this player / party their");
int newcount = resultEG[0].GetInt("totalFreeSlots") - 1;
Console.WriteLine("scratch 1 ... to ... " + newcount);
resultEG[0].Set("totalFreeSlots", resultEG[0].GetInt("totalFreeSlots") - 1);
resultEG[0].Save();
} else {
//No suitable games found, create one
Console.WriteLine("No suitable existing games have been found, creating new game");
DatabaseObject obj = new DatabaseObject();
DatabaseArray inGameFBUIDs = new DatabaseArray();
obj.Set("totalFreeSlots", 18);
obj.Set("facebookUIDs", curFBUID);
PlayerIO.BigDB.CreateObject("activeGames", null, obj, delegate(DatabaseObject resultNG) {
resultNG.Set("totalFreeSlots", resultNG.GetInt("totalFreeSlots") - 1);
resultNG.Save();
});
}
});
}
});
The issue is in the if(resultEG.Length > 0) loop, as you can see the DB is supposed to be updated with a decremented value but instead what happens is if the original value was 18 it will go down to 17 the first time but then when it reads the current DB value again as per the for(int i = 0; i <= result.Length - 1; i ++) loop which it is contained in, it reads it as 18 instead of 17 (it's original number prior to the update) and so it will update only once. Can anyone shed some light onto why this might be happening?
Thanks.