Forum BigDB some problem with LoadOrCreate

Discussion and help relating to the PlayerIO database solution, BigDB.

some problem with LoadOrCreate

Postby gnollik » May 31st, 2011, 4:29 pm

Hi, I`m try to use this code:

PlayerIO.BigDB.LoadOrCreate("racer", message.GetString(0), delegate(DatabaseObject rat)
{
if (!rat.Contains("rating"))
{
rat.Set("rating", rating + 3);
rat.Set("player_game_count", player_game_count + 1);
}
else
{
rating = rat.GetInt("rating", 0);
rat.Set("rating", rating + 3);
player_game_count = rat.GetInt("player_game_count", 0);
rat.Set("player_game_count", player_game_count + 1);
}
rat.Save();
});

message.GetString(0) - its a user name, in DB it will be a key.

As the result a new key is created, but no data is added...

The same problem with your example, a new key is created, but no data is added:

PlayerIO.BigDB.LoadOrCreate("Users", ConnectUserId,
delegate (DatabaseObject result){
if (!result.Contains("username")) {
//Empty object, initialize it
result.Set("username", "Charlie");
result.Set("age", 20);
}
result.Set("location", "London");
result.Save();
}
);
gnollik
Paid Member
 
Posts: 24
Joined: March 12th, 2011, 10:08 pm

Re: some problem with LoadOrCreate

Postby gnollik » June 1st, 2011, 10:27 am

Hi, please help! I may finish the project in nearly 2 days, but I cant do it while I am get this error.. (
gnollik
Paid Member
 
Posts: 24
Joined: March 12th, 2011, 10:08 pm

Re: some problem with LoadOrCreate

Postby Henrik » June 1st, 2011, 11:44 am

Am I getting this right, you run that code, and then a databaseobject is created under that key, but it has no properties?

Where have you checked that is has no properties? In the admin panel? By loading it again through code?

The .Save() method on DatabaseObject can take a callbacks, can you add those and check if you get an error back when saving?

http://playerio.com/documentation/refer ... bject#Save
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: some problem with LoadOrCreate

Postby gnollik » June 1st, 2011, 12:15 pm

Yes, you are right, I`m run that code, and then a databaseobject is created under that key, but it has no properties. I`m check it in the admin panel. It looks like the code in the function is not executed because I`m try to use this simple code:

PlayerIO.BigDB.LoadOrCreate("racer", message.GetString(0),
delegate (DatabaseObject result)
{
Console.WriteLine("work fine");
}
);

and Console.WriteLine("work fine"); doesnt work... So I think that the reason is not in Save() function, but in "LoadOrCreate()" function itself...

Additionally I`m use Load() function in another part of the code and it works fine...
gnollik
Paid Member
 
Posts: 24
Joined: March 12th, 2011, 10:08 pm

Re: some problem with LoadOrCreate

Postby Henrik » June 1st, 2011, 12:37 pm

You can pass two delegates to all BigDB methods, both a successcallback and a errorcallback. Can you try passing in an errorcallback that just prints out the error? Something like this I think:

Code: Select all
PlayerIO.BigDB.LoadOrCreate("racer", message.GetString(0),
    delegate (DatabaseObject result) {
        Console.WriteLine("work fine");
    },
    delegate (PlayerIOError error) {
        Console.WriteLine("error, code: " + error.ErrorCode + ", message: " + error.Message);
    }
);
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: some problem with LoadOrCreate

Postby gnollik » June 1st, 2011, 12:53 pm

Ok, I`m try to use your code but Console.WriteLine() still doesnt work... I`m already check Console.WriteLine() function and it works fine in other places of the code. And a databaseobject is created under that key like before without any problems.
gnollik
Paid Member
 
Posts: 24
Joined: March 12th, 2011, 10:08 pm

Re: some problem with LoadOrCreate

Postby Henrik » June 1st, 2011, 1:37 pm

gnollik wrote:Ok, I`m try to use your code but Console.WriteLine() still doesnt work...


Doesn't work.. how? Does it never fire the error callback? Is there something wrong with the line? What happens if you add a error callback to the Save() method, not just LoadOrCreate()?
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: some problem with LoadOrCreate

Postby gnollik » June 1st, 2011, 1:59 pm

nothing work in this place:

PlayerIO.BigDB.LoadOrCreate("racer", message.GetString(0),
delegate (DatabaseObject result)
{
HERE
}
);

any code that I insert here doesnt work. No errors, all code in this place doesnt executed...
Error callback to the Save() method doesnt show anything. It looks like all code in this place is ignored and doesnt executed...

can I use some another code without LoadOrCreate function to make this:

1. User enter, I`m check if he is already have some databaseobject in DB.
2. If he has, I`m get it, modify, and save.
3. If he hasn`t, I`m create a new databaseobject with new properties for this user.

Thanks for your help )
gnollik
Paid Member
 
Posts: 24
Joined: March 12th, 2011, 10:08 pm

Re: some problem with LoadOrCreate

Postby Henrik » June 1st, 2011, 2:35 pm

gnollik wrote:nothing work in this place:

PlayerIO.BigDB.LoadOrCreate("racer", message.GetString(0),
delegate (DatabaseObject result)
{
HERE
}
);


That piece of code only has a success callback, and if the method call fails, you'll never know. If you add an error callback to it, what happens then? If you wrap the thing in a try/catch, what happens then?

I understand that it doesn't work for you, but I need the actual error message to be able to help you.
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: some problem with LoadOrCreate

Postby gnollik » June 1st, 2011, 3:36 pm

Sorry, but as you can see bellow, I`m already try to add error callback to it:

PlayerIO.BigDB.LoadOrCreate("racer", message.GetString(0),
delegate (DatabaseObject result) {
Console.WriteLine("work fine");
},
delegate (PlayerIOError error) {
Console.WriteLine("error, code: " + error.ErrorCode + ", message: " + error.Message);
}
);

as I understand "delegate (DatabaseObject result)" - is a success callback and "delegate (PlayerIOError error)" is an error callback. In both callbacks I`m try to see something with Console.WriteLine() function, but I dont have any result. I dont get any error message... (
gnollik
Paid Member
 
Posts: 24
Joined: March 12th, 2011, 10:08 pm

Re: some problem with LoadOrCreate

Postby gnollik » June 1st, 2011, 3:45 pm

can you try to save something to my DB "racer" via "LoadOrCreate" from your side, and if you manage it send me an example of the code that you use for this. And I will try to copy/paste your code and try it from my side...
gnollik
Paid Member
 
Posts: 24
Joined: March 12th, 2011, 10:08 pm

Re: some problem with LoadOrCreate

Postby gnollik » June 1st, 2011, 6:06 pm

Oh, I`m already find the issue... The problem was that I try to use "LoadOrCreate" in the end of the game, when user left the room and it become closed... And it looks like that in the last seconds "LoadOrCreate" cant be executed correctly... So this is a new problem... Can I use some function to prevent room close for additional 5-10 seconds, while "LoadOrCreate" will add all neccessary info in DB?
gnollik
Paid Member
 
Posts: 24
Joined: March 12th, 2011, 10:08 pm

Re: some problem with LoadOrCreate

Postby Oliver » June 2nd, 2011, 11:36 am

Are you absolutely sure it's not being executed?

It might just be that you can't Console.Writeline after the room has closed.

- Oliver
User avatar
Oliver
.IO
 
Posts: 1159
Joined: January 12th, 2010, 8:29 am

Re: some problem with LoadOrCreate

Postby gnollik » June 8th, 2011, 2:51 pm

Sorry about late answer. Yes, I`m sure bacause I`m add 3 sec timer and all works fine now. But I`m have a new issue now. I`m already create a topic multiplayer/error-with-sync-or-something-else-t1732 but still not have an answer on it. Maybe you can help me with my issue:

I`m developing a game and this is how it works:

1. User connect to the server, join to the main room and wait "start".
2. When playercount in the main room is 3, the server send a name of the game room to all connected players.
3. All 3 players disconnect from the main room and connect to a new game room.
4. game start.

And all works fine while I`m use the limit on players not more than 3. But when I`m try to change it to 5, some players doesnt connect to the server. Sometimes they dont get "start" from the server (80%), and sometimes they get it but cant connect to the new game room (20%).

This is a code that I`m use on server side:

if (PlayerCount == 3)
{
this.timer2 = AddTimer(delegate
{
PlayerIO.BigDB.Load("racer", "game_name", delegate(DatabaseObject user)
{
game_count = user.GetInt("count", 0);
user.Set("count", game_count + 1);
user.Save();
foreach (Player u in this.Players)
{
u.Send("start", game_count, info_list);
}
});
}, 3000);
}

I`m add timer because I thnk that this may help to sync players but it doesnt help.. (

If you need I can provide you all code with my connect from AS3 and the server side code too.

Please advice what can be the reason of this issue...
gnollik
Paid Member
 
Posts: 24
Joined: March 12th, 2011, 10:08 pm

Re: some problem with LoadOrCreate

Postby default0 » June 13th, 2011, 10:57 am

Hi gnollik

Have had the exact same issue with LoadOrCreate. If you close a room it's callback won't be executed anymore, thus failing the code.
I found a work-around though: Load the DatabaseObjects when the user joins, store the DatabaseObject you get in a variable of the player (fe player.dbObj = myDBObj;). Then, where you have to change the data, just use player.dbObj.Set("blah", "blubb") and at the end save that (player.dbObj.Save). This solution works just fine for me.

Hope this helps you without messy timer work-arounds ;)

Oh and aside from that, this proves that I wasn't the only one with this issue ;)

Best Regards
Try to play my Game: -->BlackGalaxy<--
User avatar
default0
 
Posts: 115
Joined: February 2nd, 2010, 6:46 pm
Location: Germany


Return to BigDB