Jump to content

Best way to store game data (items etc, not player data)


Chimera
 Share

Recommended Posts

I am just curious how other are referencing and storing data for things like items, skills, etc. I have created a base class for my items, a different class for weapons, armours, and accessories, but I am wondering if it just makes more sense to store them in a json file or large array? I have to instantiate all of the items which is just as or more work than if I just created a table and used that instead. Then I can also query the table more effectively, I am not sure how I would query multiple objects using one of their properties?

 

Use this snippet of item data as an example.

Index# Armor Defense Weight Resist Spell Price Equippable By01 Cloth 1 2 --- ---- 10 FI TH BB RM WM BM02 Wooden[A] 4 8 --- ---- 50 FI TH BB RM03 Chain [A] 15 15 --- ---- 80 FI NI RM04 Iron [A] 24 23 --- ---- 800 FI NI05 Steel [A] 34 33 --- ---- 45000 FI06 Silver[A] 18 8 --- ---- 7500 FI NI RM07 Flame [A] 34 10 Ice ---- 30000 FI NI08 Ice [A] 34 10 Fire ---- 30000 FI NI09 Opal [A] 42 10 Lit ---- 60000 KN10 Dragon[A] 42 10 F/I/L ---- 60000 KN
Link to comment
Share on other sites

In the past I've done a couple things, if there are more complex objects I have put them into JSON files that I import into IndexedDB and can run more complex queries on. Other times I just embed the data in the app memory if there isn't a ton of it (e.g. lttp item data).

 

Really depends on the browser support you are targeting, what kind of querying you need, etc.

Link to comment
Share on other sites

You have the choice, either use IndexedDB as xerver said, or you can use the localStorage of the browser.

 

If you are looking to support most of the browser version I might advise you to go for localStorage (of course, if the user is cleaning his cache, he's fucked ^^').

It really depend, but for you to have an idea, you can see which one is supported on which browser :

 

IndexedDB : http://caniuse.com/#feat=indexeddb

LocalStorage : http://caniuse.com/#search=localstorage

 

In july I had to develop a website using IndexedDB but at this time, Safari was using the version 7 and it wasn't supported -_-', but now from the 7.1 it is.

 

Or if you feel like it, you can use the socket to save it online ^^.

Link to comment
Share on other sites

I don't this game should be so large that I can't utilize the memory to store everything, so with that in mind I was thinking either a large array, or JSON should be the way to go. I don't necessarily need to query the item table, I am just trying to think of how you split the items available in shops across different towns. One method is to display them based on the relative level from the player, or have a field for each item like an item tier or something and then I pull all items in that tier, or have a different object responsible for it like where they are in the story or something. 

 

Not sure which to go with, but I am trying to keep things as simple as possible. 

Link to comment
Share on other sites

Been perusing the repo you linked, really snooping is what I was doing, and it is helping me understand a bit better how I should be structuring and storing my data.

 

I do have a question, how does the 'Define' tie into the dependencies? Is this something build into javascript similar to an import, or does this use a 3rd party library like requireJS or something? 

Link to comment
Share on other sites

Been perusing the repo you linked, really snooping is what I was doing, and it is helping me understand a bit better how I should be structuring and storing my data.

 

I do have a question, how does the 'Define' tie into the dependencies? Is this something build into javascript similar to an import, or does this use a 3rd party library like requireJS or something? 

 

That repository is using require.js to organize code, that is what the define you are seeing is.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...