Forum QuickConnect Questions about simple connect and player objects

Discussion and help relating to PlayerIO's QuickConnect feature, including Facebook Connect and Kongregate Connect.

Questions about simple connect and player objects

Postby MrBiscuits » December 12th, 2011, 5:05 pm

When you register a user using SimpleRegister, how do you get it to create a playerObject for that user? I assumed that they get created automatically, but my BigDB PlayerObjects list is still empty after I've created a user.

I want to give the player certain properties when they sign up (number of credits and so forth), but I am unsure how to do that.
There isn't a UserRegistered method I can override on the server side and even if there was I'm not sure how you would create a playerObject and add fields to it.

Any help would be really appreciated.
MrBiscuits
 
Posts: 26
Joined: May 15th, 2011, 8:09 pm

Re: Questions about simple connect and player objects

Postby Henrik » December 12th, 2011, 5:23 pm

Nothing is saved to the PlayerObjects table until you actually put data in the PlayerObject of the player, and call Save() on it.

The easiest way to add data on registration is to always check if the PlayerObject has the properties you want, and if it doesn't you add it and save it. Check the second piece of example code on this page:

http://playerio.com/documentation/bigdb/playerobject
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: Questions about simple connect and player objects

Postby MrBiscuits » December 13th, 2011, 10:50 pm

Great thanks that works.

I'm having a problem when I update the playerObject on the server and saving it using PlayerObject.Save().

The client requests the updated playerObject using:

client.bigDB.loadMyPlayerObject(function(_obj:DatabaseObject):void

but the data doesn't seem to have been updated in time so the client still receives the old data.

If I put a breakpoint on the server after the PlayerObject.Save() and wait for a few seconds, then allow it to continue (it sends a receipt to the client saying the data is updated, which then calls loadMyPlayerObject), the data gets updated ok on the client.

Is there a way to fix this?
MrBiscuits
 
Posts: 26
Joined: May 15th, 2011, 8:09 pm

Re: Questions about simple connect and player objects

Postby Henrik » December 14th, 2011, 11:14 am

All BigDB methods are asynchronous, which means that they return immediately, they don't wait for the operation to complete. If you want to send a message to the client to load an object you saved server-side, you need to call Save with a success callback, and in that callback you send a message to the client to reload the object, because when that callback fires, the object is definitely saved.
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: Questions about simple connect and player objects

Postby MrBiscuits » December 14th, 2011, 12:45 pm

Ah right that makes sense.

What is the syntax for adding a callback function name to the playerObject.Save() function?

Edit: I've figured it out now

player.PlayerObject.Save(delegate()
{
FunctionName(player);
});

Also is there a C# server reference anywhere?
MrBiscuits
 
Posts: 26
Joined: May 15th, 2011, 8:09 pm

Re: Questions about simple connect and player objects

Postby Henrik » December 14th, 2011, 3:42 pm

MrBiscuits wrote:Also is there a C# server reference anywhere?

Right here: http://playerio.com/documentation/refer ... ltiplayer/

:-)
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm


Return to QuickConnect



cron