Forum QuickConnect Knowing if user has dbobject or not

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

Knowing if user has dbobject or not

Postby samsonadze » January 12th, 2013, 5:35 pm

Hey!

When user will be registered with facebookOAuthConnect,how can i create BigDBObject for it? i mean how can i get if user has dbobject already or not?
i have this code:
Code: Select all
function loadedMyobjcet(object:DatabaseObject):void
   {
      if (!object)
      {
         object.fbname = fbname;
         object.highscore = 0;
         object.experience = 0;
         ...
                        object.save();

but it not works! it isnt creating my db object
C#
samsonadze
 
Posts: 122
Joined: August 29th, 2012, 2:39 pm

Re: Knowing if user has dbobject or not

Postby samsonadze » January 12th, 2013, 5:37 pm

this is just example of my code,dont worry about syntax! ;)
when i run it it not throws any error -_- :|
C#
samsonadze
 
Posts: 122
Joined: August 29th, 2012, 2:39 pm

Re: Knowing if user has dbobject or not

Postby Benjaminsen » January 12th, 2013, 6:19 pm

I suggest you use loadOrCreate to automatically create a database object for new users.

Then either use a property on that object to determine if the user existed:

Code: Select all
if(!object.created){
   object.created = true;
   ....
   object.save()
}


Even better, simply apply default values where needed.

Code: Select all
if(!object.created){
   object.myproperty = object.myproperty || "default value"
}
Benjaminsen
.IO
 
Posts: 1444
Joined: January 12th, 2010, 11:54 am
Location: Denmark

Re: Knowing if user has dbobject or not

Postby samsonadze » January 12th, 2013, 6:35 pm

well,i already tried that,but when i use loadOrCreate function it throws an error .idk why but i think it's because the user object already exists.well i already figured out how to fix it. with this way:

Code: Select all
var account:Object = {};
//when i load BigDB object then i type account = BigDBobject
then i type: if(!account){
//bigDB code here....
}


and it works! :) thanks anyways
C#
samsonadze
 
Posts: 122
Joined: August 29th, 2012, 2:39 pm

Re: Knowing if user has dbobject or not

Postby Benjaminsen » January 12th, 2013, 6:37 pm

samsonadze wrote:well,i already tried that,but when i use loadOrCreate function it throws an error .idk why but i think it's because the user object already exists.well i already figured out how to fix it. with this way:

Code: Select all
var account:Object = {};
//when i load BigDB object then i type account = BigDBobject
then i type: if(!account){
//bigDB code here....
}


and it works! :) thanks anyways


Take a look at loadMyPlayerObject :)
Benjaminsen
.IO
 
Posts: 1444
Joined: January 12th, 2010, 11:54 am
Location: Denmark


Return to QuickConnect



cron