This is what I am doing:
When a user joins the game, this is called for that user.
- Code: Select all
public void loadUser(Player player) {
PlayerIO.BigDB.LoadOrCreate("PlayerObjects", player.ConnectUserId,
delegate(DatabaseObject result)
{
if ( !result.Contains("username") ) { result.Set("username", "SimpleUser"); }
if ( !result.Contains("level") ) { result.Set("level", 1); }
if ( !result.Contains("exp") ) { result.Set("exp", 0); }
result.Save();
player.Send( "loadFinished", result.GetString("username"), result.GetInt("level"), result.GetInt("exp") );
if (result.Contains("username")) { Broadcast("UserJoined", result.GetString("username")); }
else { Broadcast("UserJoined", "Unknown"); }
}
);
}
Next when a user wishes to change his name he calls this function:
- Code: Select all
public override void GotMessage(Player player, Message message) {
switch(message.Type) {
case "NameChange":
PlayerIO.BigDB.Load("PlayerObjects", player.ConnectUserId, delegate(DatabaseObject user) { user.Set("username", message.GetString(0)); user.Save(); });
break;
}
}
I'm still in the early stages of development, and I would like to know if I am using Player DB correctly or not, so I can get into the swing of things right away. I've tried following the documentation best I can, but I find it very hard to understand so I find myself testing and failing a lot of ways of going about this.
EDIT: One big concern of mine would be running all these delegate in a fast paced environment. I am curious if they would be reliable? I've found calling a delegate and then doing something else does not run the program in order, instead there is a slight (Very noticeable) delay when a delegate function/method is called.