Jump to content
  • Advertisement
Sign in to follow this  
kablammyman

saving arrays to a database

This topic is 2594 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I am looking for some general advice for saving arrays to a database.

So, a lil background. I am working on a facebook app that allows you to create an avatar. The avatar has lots of different clothing types (shirts, pants, hats, neck items etc). Right now, I save things locally in a string array. The array is just a list of the types of items the avatar has, a file name, and any extra info like the color. This system works fine, but now that it will soon be on Facebook, we will utilize a database to save these things, as well as any other things the user may have purchased. This way, the user is not tied to a single computer to use the app... wherever there is facebook, the user will be able to access the items he/she has saved and purchased. Also, there are some things that will be locked from the start, and when you purchase them, the items will unlock. I have a way to lock and unlock things, bu saving them to a database is a differnt matter.

So, since there's no built in arrays in a database, I am looking for general advice on how to handle this efficiently. I dont want to have to index each string in the string array and save them one at a time. I hear that xml can help with things, but I still need to do some research on how and why. Anyway, any help is appreciated.

Thanx.

Share this post


Link to post
Share on other sites
Advertisement
Take typical 'inventory'-style table structure from RPGs:


[font="'Lucida Console"]'inventory' table:[/font]
[font="'Lucida Console"]type size name description[/font]
[font="'Lucida Console"]int 4 inventoryId primary key for inventory table[/font]
[font="'Lucida Console"]int 4 personId foreign key relates to person this inventory item is 'equipped' on[/font]
[font="'Lucida Console"]int 4 locationId foreign key relates to the location on the person this inventory item is equipped (head, body, left wrist, etc)[/font]
[font="'Lucida Console"]varchar 255 articleName name of the inventory item[/font]
[font="'Lucida Console"]varchar 255 filename the name of the file (from your description)[/font]
[font="'Lucida Console"]varchar 255 color color (assuming RGB string that can be later parsed)[/font]
[font="'Lucida Console"]
[/font]
[font="Arial"]to select all of one person's equipment:[/font]
[font="'Lucida Console"]select * from inventory where personId = 'some-unique-identifier'[/font]

The unique identifier should be some completely unique (UUID, username, or whatever FB API gives you) identifier which you can associate with users.

If you normalize your design, storing stuff like this becomes trivial.

Share this post


Link to post
Share on other sites
Thanks for the quick response. My code (in C#) to store the items is similar to what you have in your SQL example, but I'm still not sure how to efficiently save the items from C# to SQL. I may be missing your point, but I just want to take my string array and do some code magic to produce a "format" that SQL will happily accept since it cant just save my string array. You see what i mean? Forgive me if I misunderstood your advice. thanks for your help so far :)

Share this post


Link to post
Share on other sites
You seem to be so new to SQL that I have to recommend that first you read up on how to use SQL databases. You can check out w3schools for example: http://www.w3schools.com/sql/default.asp

Once you have grasped how databases work you should have no problem solving your problem by yourself. The reason I'm not giving a complete example is because I don't think you understand how databases work and it is better that you learn it first.

Share this post


Link to post
Share on other sites
When I was doing SQL-type work last year I was serializing datasets and sending them over a network. The serialization used something called XSLT (I think) to translate the serialized XML into a more readable format, and back. The actual output xml was used in conjunction with a Visual Studio tool called XSD to generate a schema file and then C# classes. I think I used:

xsd Data.xml
xsd /classes /namespace:YourNamespaceHere Data.xsd

This type of technique could be automated with a shell script I am sure and maybe generated/executed at runtime. I am not a very experienced developer so I can't say for sure. But if you are interested it might be an idea to look into the xsd.exe documentation on MSDN.

Either way, it was for a business application and I am not sure if it is efficient enough to use in a real game.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!