I am making a minecraft kind of game. In which I have 100s of objects and their crafting recipe.

Now I want to store them inside the program, ie I cannot load external files. Everything must be inside class for now. In future I might be able to use databases, once the game gets more traction.

All these objects will have addition properties like shootable,purchase cost,etc etc.

Some also have array property like

{ research1: unlocks{ object1:50%, object2:100% }},

{ research2: unlocks{ object1:50% }}.

But all these objects will be constant with an exception of "locked" boolean.

If I do a huge database I'll also have to search data using filters on they keys like we do on sql. Example: "Give me all Researches that are unlocked and that unlocks object1"

What will be the best datastructure to store them? Thanks.

  • 1
    \$\begingroup\$ Which language are you using for the game? \$\endgroup\$ – wip Dec 10 '17 at 14:19
  • \$\begingroup\$ I am using AS3 to create an AIR mobile game \$\endgroup\$ – Shantanu Dec 10 '17 at 16:25

100s of objects is not a large amount of data for current machines (computers, phones, consoles).
For only 100s of objects with different properties, you could save them as a comma-separated-values file (.csv) that can be opened and edited with Excel or similar worksheet software.
You can write run-time queries that will take a negligible time to loop around the list of objects and find the ones with the correct properties.
If you want to speed up the loading/saving of this array of data, you can try to serialize it in a binary format instead of the text-based .csv format.

For the properties of variable size (the arrays you mentioned) , if you decide the biggest possible number of items, you can hard-code this in the serialization and leave the unused array items as "empty".
If there is no limit... then you need a field to store the number of items, and then fields to store this data. You cannot use a simple flat format such as .csv in that case (unless you store arrays in different files referred to by some identifiers).

|improve this answer|||||
  • \$\begingroup\$ I am using AS3, and I cannot use an external file so I have to code all that inside the program. Like using a static object type variable. I have never made a game that has like 500 data for game objects. What are the common practices programmers uses to store large data for this kind of games? \$\endgroup\$ – Shantanu Dec 10 '17 at 16:33
  • \$\begingroup\$ @Shantanu I don't remember ActionScript well, however in C you can write something like this: onlinegdb.com/BkXhLLsbM \$\endgroup\$ – wip Dec 11 '17 at 0:52
  • \$\begingroup\$ AS3 is very close to JAVA. so anything in JAVA will also do. So basically you are saying is i should create a class,define datatypes and then use that class object to store all those data? Currently I am storing them as kind of JSON. \$\endgroup\$ – Shantanu Dec 11 '17 at 9:58
  • \$\begingroup\$ Yes. JSON is fine too. The point is that I do not think you should be using a more complex database solution, they are usually slow and not suited to real-time game development. Some of them might be used on game servers to store the data for multi-player games or MMOs, but it does not seem that it is what you are trying to do. \$\endgroup\$ – wip Dec 11 '17 at 16:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.