Forum BigDB Key of newly created Object ?

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

Key of newly created Object ?

Postby MaToMaStEr » July 29th, 2010, 5:28 am

Hi !

I'm new to Player.IO and want to develop my first game. I just have some problem though

For my idea I would need to know the number of objects stored in certain Table, cause I want to assign each element a unique (but known) Key, so... using an index would be great, something like Auto Increment in SQL.... is this possible ??

One workaround I was thinking was to make an object in the table with an array holding all of the Keys. But for this... I would need to know the randomly generated Key of the object i've just created... so I can add it somehow to the Array.

EDIT: I think I got it. I can use the callback of the createObject() function to get the key of it object! nice...
Now... how would I load the Keys Array... add the new Key, and then overwrite the one in the DB with the updated one ?

Could anyone help me pleease ?
Ok... Thanks in advance for your help !!
Last edited by MaToMaStEr on July 29th, 2010, 4:04 pm, edited 1 time in total.
MaToMaStEr
 
Posts: 4
Joined: July 29th, 2010, 3:45 am

Re: Key of newly created Object ?

Postby Benjaminsen » July 29th, 2010, 11:00 am

Can you describe your use-case a bit more? What is the goal you are trying to achieve.
Benjaminsen
.IO
 
Posts: 1444
Joined: January 12th, 2010, 11:54 am
Location: Denmark

Re: Key of newly created Object ?

Postby MaToMaStEr » July 29th, 2010, 2:46 pm

ok, yeah sure.
Basically, I want the player to be able to create Objects and then store them in the DB table.
This Table should be accessible for all the players.
Now, for the important part; there should be an option to load a random object from the Table.
That's why I want to know the Keys of the objects contained.

I was thinking also about having an object with a counter... so the key of the new object is counter+1, and the counter is incremented on every Save. The problem with this though, is... what happens if I delete an object from the table ?

Well... Thanks for replying. I hope someone can give me some ideas
Thanks !!
MaToMaStEr
 
Posts: 4
Joined: July 29th, 2010, 3:45 am

Re: Key of newly created Object ?

Postby UnknownGuardian » July 29th, 2010, 4:41 pm

You could be loading indexes rather than keys, using
Code: Select all
loadRange()
I'd do the random DB object on the server itself, and return it, preventing you from having to send all that mess to the client.
UnknownGuardian
 
Posts: 94
Joined: May 25th, 2010, 5:11 am

Re: Key of newly created Object ?

Postby MaToMaStEr » July 29th, 2010, 8:32 pm

thanks !
Right now I got it to work.
I have , as I said at the beginning, an Objects which contains an array of Keys.
Then, when a new object is created, I use the callback function to retrieve its random Key.
Then... I load the Keys-Holder, push the new Key and Save it again.
I can now pick any random key from the KeysHolder.

I will have to develop now an algorithm to handle when I delete an Object. I'll find the index in the KeyHolder and splice the array.

Thanks for the replies !
any other (easier) way of doing this ?
MaToMaStEr
 
Posts: 4
Joined: July 29th, 2010, 3:45 am

Re: Key of newly created Object ?

Postby Oliver » July 30th, 2010, 10:30 am

Are you doing that client-side or server-side?

Another way of solving it would be to generate the list of keys periodically by looping over an index, say once a day or something ( i don't know the requirements of your game, but that might be easier)

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

Re: Key of newly created Object ?

Postby MaToMaStEr » July 30th, 2010, 7:47 pm

Oliver wrote:Are you doing that client-side or server-side?

Another way of solving it would be to generate the list of keys periodically by looping over an index, say once a day or something ( i don't know the requirements of your game, but that might be easier)

- Oliver


youre right... I think that would be better.
The thing is... I'm dont know yet all the functions so... how would you loop over some objects with a Key ?
MaToMaStEr
 
Posts: 4
Joined: July 29th, 2010, 3:45 am

Re: Key of newly created Object ?

Postby Oliver » August 2nd, 2010, 10:07 am

The thing is... I'm dont know yet all the functions so... how would you loop over some objects with a Key ?


You can't just loop over all objects directly, but you can loop over all objects in an index. So you'll have to ensure that there exists an index for the BigDB table which all objects are in.

There is more detailed documentation about BigDB indexes if you want:
http://playerio.com/documentation/bigdb/indexes

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


Return to BigDB