Forum BigDB avoiding BigDB objects auto-sort?

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

avoiding BigDB objects auto-sort?

Postby QiX » July 31st, 2010, 3:04 pm

Hi,

I've noticed that the objects in the Tables I created are being auto-sorted according to its keys values.
For example, I have 3 tables that represents grids (map grids), and each object in the greed is represented as x,y (thats the key)
so instead of having it sorted the way it was created: [(0,0), (0,1), (0,2)...] i get it as [(0,0), (0,1), (0,11)...]
The reason I'm saving the keys this way, is in order to keep the key as unique as possible without need of more information to describe the object (and because it has a specific indices, i was thinking its the best way).
my problem is that the client side needs to draw a map according to the content of the objects, so it needs to get the objects content in a specific indices order, just like a 2 loops (one is an internal loop) that runs from 0 to n would generate.

lets say that the objects content represents a color (for example. 0 = yellow, 1 = green, 2 = red)
so if my table supposed to represents a NxN table, its impossible for me to build the grid map as I want as long as my object key is the indices.

Anyway, I hope i'm clear enough, if not excuse me.
I was wondering if anyone that had to do that before has an Idea to avoid this problem, or maybe to
QiX
QiX
 
Posts: 34
Joined: July 22nd, 2010, 4:41 pm

Re: avoiding BigDB objects auto-sort?

Postby Benjaminsen » July 31st, 2010, 3:35 pm

If you are working with limited size maps, I would suggest that you simply store the entire map in a single object as the system, supports complex objects such as two dimensional arrays.

An example would be
Code: Select all
client.bigDB.loadOrCreate("maps", "mymap", function(o:DatabaseObject):void{
   o.world = [
      [1,1,1,1,1],
      [1,0,0,0,1],
      [1,0,0,0,1],
      [1,0,0,0,1],
      [1,1,1,1,1]
   ]
   o.save()
})
Benjaminsen
.IO
 
Posts: 1444
Joined: January 12th, 2010, 11:54 am
Location: Denmark

Re: avoiding BigDB objects auto-sort?

Postby QiX » July 31st, 2010, 3:42 pm

Hi Chris, Thanks for the fast response!

But maybe I need to draw the big picture here.
As I mentioned, each Table represents a grid map.
each object in the table represents a territory.
each territory has few properties (x, y, content, owner)
when content is an integer, which According to it I can set the appropriate icon in the client side (the game has 2 sides fighting each other)
and owner is the ID of the player which this specific territory belongs to.

a territory can be overtaken so i need to possibility to change the content and owner properties.
plus, in the future we might want to add properties to each territory (this is still early development, so changes might take place).

my question is, if I follow your suggestion, will I be able to change specific cells in the object that represents the 2 dimensional array?
QiX
QiX
 
Posts: 34
Joined: July 22nd, 2010, 4:41 pm

Re: avoiding BigDB objects auto-sort?

Postby Oliver » August 2nd, 2010, 9:59 am

my question is, if I follow your suggestion, will I be able to change specific cells in the object that represents the 2 dimensional array?


Yes.

When you change bigdb objects and call save, only the changes you've made are submitted to the database and applied to the "master" object.
User avatar
Oliver
.IO
 
Posts: 1159
Joined: January 12th, 2010, 8:29 am


Return to BigDB