I am making an async multiplayer game and i am using BigDB only on the serverside to store/restore data between sessions. I only use BigDB methods on GameStarted() and GameClosed() methods. But I fail, even so simple they are.
Only delegate callbacks are the real problem, since i fail with them on two ways.
First one is happening when i try to use a BigDb callback to change an outer scoped variable
- Code: Select all
bool isExist= false;
PlayerIO.BigDB.LoadRange("TableName", "IndexName", new object[] { IndexParam}, null, null, 10,
delegate(DatabaseObject[] result)
{
//Do Something
if(result.Length > 0)
{
isExist= true;
}
}
);
if(isExist)
{
//THIS FAILS SINCE DELEGATE METHOD IS POSSIBLY NOT CALLED YET
PlayerIO.BigDB.LoadOrCreate("TableName","ObjectName" ,
delegate(DatabaseObject result)
{
//Index mostly gives wrong value as expected
result.name = myArray.name;
}
);
}
this one can`t be solved by moving the last if(isExist) block entirely in to the delegate callback because bigDB methods can not be run inside delegates. And also my GameStarted function will be ended before BigDB delegate callback ends, so players could even interact with server before my database is loaded! Thats horrible!
Second one is happening when i try to use a BigDB method in a for loop. If i use index iterator of for in the delegate callback, index is mostly addressing wrong value because my for loop iterate before delegate callback
- Code: Select all
for(int index = 0; index < myArray.Count; index ++)
{
PlayerIO.BigDB.LoadOrCreate("TableName","ObjectName_" + index ,
delegate(DatabaseObject result)
{
//Index mostly gives wrong value as expected
result.name = myArray[index].name;
}
);
}
So is there any easy solution to solve these situations without using complicated locks?
Is there any wait methodology for delegate callbacks?
I just want to use BigDB methods like they are synchronous.
Thanks for help!