I'm currently trying to use a DatabaseArray to track a group of players. Essentially this means that when a player joins, they're added to a BigDB object that contains an array. When they leave, they're removed. Here's an example of the server code that leads up to this point:
- Code: Select all
public override void UserJoined(Player player) {
PlayerIO.BigDB.Load("Groups", "testGroup", delegate(DatabaseObject group)
{
DatabaseArray characters = group.GetArray("characters");
characters.Add(player.Id);
group.Save();
});
}
public override void UserLeft(Player player) {
PlayerIO.BigDB.Load("Groups", "testGroup", delegate(DatabaseObject group)
{
DatabaseArray characters = group.GetArray("characters");
for (var i = 0; i < characters.Count; i++)
{
if ((int)characters[i] == player.Id)
{
characters.RemoveAt(i);
}
}
group.Save();
});
}
At this point, I can connect a number of clients and see these values reflected in BigDB. Similarly, as each client is disconnected we see the value being removed in turn. Everything works as expected until...
Only one client remains.
If I call the DatabaseArray.RemoveAt() method on an array with only one value, the removal fails and I start to see the repeated warning, "Some code has been running for longer than will be allowed in the live enviroment. ..."
If anyone has any input on this, I'd greatly appreciate it. Thanks.