Forum BigDB PlayerObject Has no properties.

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

PlayerObject Has no properties.

Postby Normero » January 13th, 2011, 3:32 pm

Yo, I got my game working quite good. Now I'm trying to implement a score and experience saving system.

I got stuck on loading and saving scores in the serverside code.

I have playerObjects with 4 properties:
wins
experience
totalScore
played

I'm trying to save totalScore like this:
Code: Select all
player.GetPlayerObject(delegate(DatabaseObject obj)
                {
                    Console.WriteLine("Retrieved playerobject, properties: "+obj.Properties.Count);
                    if (obj.Contains("totalScore"))
                    {
                        obj.Set("totalScore", obj.GetInt("totalScore") + player.score);
                        obj.Save();
                    }
                });

but the WriteLine function gives me: Retrieved playerobject, properties: 0;


Registration for SimpleUsers in AS3 finishes like this:
Code: Select all
client.bigDB.loadMyPlayerObject(function(obj:DatabaseObject):void{
            obj.experience = 0;
            obj.totalScore = 0;
            obj.played = 0;
            obj.wins = 0;
            obj.save();
         });

That worked fine and It creates the objects just fine.

I don't get why the serverside code isn't working. Am I doing something wrong?

I'm testing this in Development server.
Normero
 
Posts: 20
Joined: August 14th, 2010, 1:26 pm

Re: PlayerObject Has no properties.

Postby Normero » January 13th, 2011, 3:42 pm

Oh I think I get it.

I changed my code to this:
Code: Select all
player.GetPlayerObject(delegate(DatabaseObject obj)
                {
                    Console.WriteLine("Retrieved playerobject, properties: "+obj.Properties.Count);
                    if (obj.Contains("totalScore"))
                    {
                        obj.Set("totalScore", obj.GetInt("totalScore") + player.score);
                    }
                    else
                    {
                        obj.Set("totalScore", player.score);
                    }
                    obj.Save();
                });

My original playerObject was called simpleKoningRobert.

When I did this it created an object called KoningRobert.

I think it's because when I login, I do this:
Code: Select all
client.bigDB.loadMyPlayerObject(function(obj:DatabaseObject):void{
                     myName = client.connectUserId;
                     myName = myName.substring(6);
                     trace(myName);
                     trace("Loaded", obj);
                     PlayerIO.connect(
                        stage,                        //Referance to stage
                        "presidenten-ojtxsvqjemohy2k2huvig",         //Game id (Get your own at playerio.com)
                        "public",                     //Connection id, default is public
                        myName,                  //Username
                        "",                           //User auth. Can be left blank if authentication is disabled on connection
                        handleConnect,                  //Function executed on successful connect
                        handleError                     //Function executed if we recive an error
                     );
                  })

So does my serverside code then use the substringed name as id?

I guess I can fix it now.
Normero
 
Posts: 20
Joined: August 14th, 2010, 1:26 pm

Re: PlayerObject Has no properties.

Postby Oliver » January 14th, 2011, 10:55 am

The key of the playerObject is exactly the ConnectUserId used to connect to Player.IO. In the case of QuickConnect, it's something like simple<Username> for simple users, fb<FbUserId> for facebook users etc.
User avatar
Oliver
.IO
 
Posts: 1159
Joined: January 12th, 2010, 8:29 am


Return to BigDB