Forum BigDB Need to load specific playerobjects

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

Need to load specific playerobjects

Postby itsmylifesoham » October 10th, 2011, 5:55 am

Hi,

I wanted to use benjaminsens presence server project.
Briefly it goes something like setting a onlinestatus property on the playerObject of a person who just joined.and removing this property when the user left.
What i want to do is load only those playerObjects from the "PlayerObjects" table which have this property on my client side.
I tried the loadRange however it requires an index. And its mentioned that an index should be a property thats present on all my playerObjects.

So how do i do this!
thanks :)
itsmylifesoham
 
Posts: 36
Joined: June 27th, 2011, 9:08 am

Re: Need to load specific playerobjects

Postby Henrik » October 10th, 2011, 10:25 am

You create an index in the BigDB admin panel, give it the name "Onlinestatus", and add a single property to it called "onlinestatus", of the type boolean.

Then, in your code, you can do the following:

Code: Select all
PlayerIO.BigDB.LoadRange("PlayerObjects",
    "Onlinestatus",
    new object[] { true },
    null,
    null,
    100,
    delegate(DatabaseObject[] result) {
        //Do something with the objects here.
    });
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: Need to load specific playerobjects

Postby itsmylifesoham » October 10th, 2011, 12:33 pm

Thanks Henrik,

i didnt get why should it be a boolean?
the "onlinestatus" property is not a property set on all the playerObjects. So i think we cannot add it as an index property.
Also the "onlinestatus" property that we add to a playerObject when a user joins a presence room is not of type boolean,

its of type databaseobject having 3 sub properties - state , timeseen, presentInRoomID

So just want to know if its right to set the index property as "onlinestatus" as a boolean.

Thanks :)
itsmylifesoham
 
Posts: 36
Joined: June 27th, 2011, 9:08 am

Re: Need to load specific playerobjects

Postby Henrik » October 10th, 2011, 12:53 pm

Oh, you don't need to have the indexed property on all objects for the index to work. Objects that don't have the property, or have it but of the wrong type, simply won't be part of the index, and all load range calls you make will return objects that both have the property and match it.

You can't index on a property of type Object, but you want to find all objects that have that property, right? So what you have to do is make an index on any subproperty of it. I suggest you make an index on "onlinestatus.state", and then you just call load range with null for path, start, and stop, and you'll get all objects in the index, sorted by state.

I don't know if ordering is important, if you make the index on "onlinestatus.timeseen" instead you'll get it ordered by that, which should allow you to easily get either fresh or old users.
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: Need to load specific playerobjects

Postby itsmylifesoham » October 10th, 2011, 12:57 pm

gr8! tht helps! :) thank you.
itsmylifesoham
 
Posts: 36
Joined: June 27th, 2011, 9:08 am

Re: Need to load specific playerobjects

Postby itsmylifesoham » October 10th, 2011, 9:04 pm

Hi henrik,

I dont know if i have hit a bug or not, but i need to ask something.
I did everything as you mentioned. Now as you know, when a userleaves the presence room, we remove the onlinestatus property on his playerObject. However i found that i am unable to remove a property on a playerObject that has been used also an index property.

If i am removing the index property then the lines work fine

userleft()
{
player.PlayerObject.Remove("onlineStatus");
player.PlayerObject.Save();
}

however if index has a property defined as online status the save is not working!
is this expected?

thanks.
itsmylifesoham
 
Posts: 36
Joined: June 27th, 2011, 9:08 am

Re: Need to load specific playerobjects

Postby Henrik » October 11th, 2011, 1:27 pm

That shouldn't happen. Do you get an error message from the save? Pass in an error callback to grab it.
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm


Return to BigDB



cron