I'm trying to use Optimistic Locking for BigDB in my game and getting this error:
>Error: Cannot create circular references inside database objects
I'm pretty sure the error is because I am sending the same reference to a databaseObject background the same function when it is unable to save to the database. If that is the problem, does anyone have any better suggestions for how to accomplish this or how to copy a DatabaseObject into a new one?
Here's my code for this (it's a function that processes messages that get added to a player's message queue, and sometimes multiple messages are being sent at the same time, hence the optimistic locking):
- Code: Select all
private void SendInfoMessage(string playerID, DatabaseObject messageObject)
{
// Add message to the owning player's object
PlayerIO.BigDB.Load("PlayerObjects", playerID, delegate(DatabaseObject playerObject)
{
if (playerObject != null)
{
DatabaseArray messagesArray = playerObject.GetArray("messages");
messagesArray.Add(messageObject);
playerObject.Save(true, null, delegate(PlayerIOError error)
{
// if the player object is currently being saved, retry saving by loading fresh version
if (error.ErrorCode == ErrorCode.StaleVersion)
{
SendInfoMessage(playerID, messageObject);
}
});....