- Code: Select all
PlayerIO.BigDB.LoadOrCreate("PUD", connectedPlayer.Name, delegate(DatabaseObject savedData)
{
trace("loaded saved data");
DatabaseArray savedRequests = savedData.GetArray("r");
if (savedRequests == null)
{
savedRequests = new DatabaseArray();
savedData.Set("r", savedRequests);
trace("saved data was null");
}
foreach (DatabaseObject request in requests)
{
DatabaseObject requestToSave = new DatabaseObject();
requestToSave.Set("t", request.GetString("t"));
requestToSave.Set("n", request.GetString("n"));
savedRequests.Add(requestToSave);
trace("added request");
}
connectedPlayer.Send("req");
trace("sent notification of request");
requests.Clear();
trace("cleared requests");
result.Save();
trace("saved result");
savedData.Save();
trace("saved saveData");
});
I got tired of typing Console.WriteLine every time, so I made a function called trace. Anyway, everything traces up to the "sent notification of request", the "cleared requests" never traces, and it doesn't happen (or at least it doesn't save it if it does happen) because when I check the table in the admin, I still see the array that I'm trying to clear. Am I doing something wrong?
On a side note, I think I found a bug. In the for each loop, if I do:
- Code: Select all
savedRequests.Add(request);
I get an error about circular references. requests and savedRequests are both DatabaseArrays, but requests is in a different table. It would seem this is odd behavior to consider it a circular reference if it's in a different table. I was expecting that it would just replicate the DatabaseObject and put it in the new DatabaseArray. Maybe that would be illogical, it's just what I was expecting, so maybe this isn't even a bug.