Jump to content

  • Log In with Google      Sign In   
  • Create Account

How to code game data


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 Flurrih   Members   -  Reputation: 107

Like
0Likes
Like

Posted 10 October 2013 - 11:21 AM

Hello!

 

At the begining I'd like to present myself as this is my first post here. I'm Tomek [Tom, Tomas etc], I'm 18 from Poland, I know some of C++, mostly basics.

 

I just have couple of questions that I can't find clear answer for it, or maybe just can't find it.

 

1. How do I code game inventory just like RPG games?

 

2. How to create item data?

 

I was trying to create it in dat file. Using fstream for that, but I find it difficult to manage line by line, it's not that simple.

I just want to know if I'm going right way with fstream, maybe there are bettter ways you used?

What I had in my mind, I want it to be sorted by, for example: ID / Name / Level / Class... so each item has their own properties.

 

I was trying to make registration system and stuff, but I can't get SQLite lib to work with VS12 [keep getting errors] so I will leave that for later.

 

 

I want to mention I just need key words from you, so I can google and learn it. I don't need you to explain me every detail, just if I will have troubles in understading I will ask you to do. This is not gonna be game at the begining, it's just for experiencing. Not gonna go farer than console app at the moment.

 

Thank you in advance.

 



Sponsor:

#2 Servant of the Lord   Crossbones+   -  Reputation: 21046

Like
6Likes
Like

Posted 10 October 2013 - 11:33 AM

Google 'serialization', 'JSON', 'XML'

 

A player's inventory could be as simple as: std::vector<YourItemClass>


It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#3 jHaskell   Members   -  Reputation: 1088

Like
0Likes
Like

Posted 10 October 2013 - 11:50 AM

I'd also like to add, if your intent is to have a fairly extensive database of items, you're absolutely going to want some form of easy to use item editor utility that will allow you to easily add items to your database and edit items in your database.  This idea eventually extends to nearly every aspect of your game.  Class editors, monster/npc editors, level editors, quest system editors, etc.  These are preferably all wrapped up into a single game editor that gets used to create all the various data that composes the tangibles of your game.

 

You should also look into the factory pattern (and abstract factory pattern) for a popular method of wrapping and abstracting these content databases from your game code.


Edited by jHaskell, 10 October 2013 - 11:52 AM.


#4 Nypyren   Crossbones+   -  Reputation: 4798

Like
1Likes
Like

Posted 10 October 2013 - 02:04 PM

Most large games I've worked on do it like this:

 

1. The data is entered into a spreadsheet or SQL database using whatever app you want (Excel, OO, Google Spreadsheet, SQL).  You can lay this out however you want (simple row/column grid all the way up to a fully normalized database).

 

2. The spreadsheet or database is scanned for the data, and stored however you feel is most appropriate for your game (custom binary form, protobuf, XML, JSON, etc).  This step typically takes database-style table-based data (i.e. if an inventory item has a variable length list of crafting ingredients, the crafting ingredients would be normalized as a separate sheet/table in the input spreadsheet/database) and turns it into more typical hierarchical data structures (i.e.  "Item.CraftingIngredients[0]").

 

3. The game loads the data into the data structure you feel is most appropriate for your game (a simple list, an associative array with unique IDs, a full-on SQLite database, etc).  Excessively large data sets may be hosted on a web service that can be fetched from 100 items (or so) at a time.

 

 

The large games I've worked on have all used Excel spreadsheets for data entry and associative arrays (Dictionary<string,InventoryItem>) for runtime storage.


Edited by Nypyren, 10 October 2013 - 02:09 PM.


#5 Flurrih   Members   -  Reputation: 107

Like
0Likes
Like

Posted 10 October 2013 - 03:03 PM

Most large games I've worked on do it like this:

 

1. The data is entered into a spreadsheet or SQL database using whatever app you want (Excel, OO, Google Spreadsheet, SQL).  You can lay this out however you want (simple row/column grid all the way up to a fully normalized database).

 

2. The spreadsheet or database is scanned for the data, and stored however you feel is most appropriate for your game (custom binary form, protobuf, XML, JSON, etc).  This step typically takes database-style table-based data (i.e. if an inventory item has a variable length list of crafting ingredients, the crafting ingredients would be normalized as a separate sheet/table in the input spreadsheet/database) and turns it into more typical hierarchical data structures (i.e.  "Item.CraftingIngredients[0]").

 

3. The game loads the data into the data structure you feel is most appropriate for your game (a simple list, an associative array with unique IDs, a full-on SQLite database, etc).  Excessively large data sets may be hosted on a web service that can be fetched from 100 items (or so) at a time.

 

 

The large games I've worked on have all used Excel spreadsheets for data entry and associative arrays (Dictionary<string,InventoryItem>) for runtime storage.

 

So from my understanding, please correct me if I'm wrong, I should start off writing the item data in app like excel [just example, excel seems to be less complicated than sql - I cant get the SQLite lib to work with my IDE], then it's being scanned for data and stored in XML file [aswell example, I already went deeper into XML] and then the data is loaded in game.

 

Just a question, how is the XML handling data from excel?



#6 Nypyren   Crossbones+   -  Reputation: 4798

Like
0Likes
Like

Posted 10 October 2013 - 07:21 PM

Usually you have to save the Excel file out as some other format before beginning step 2. Dealing with Excel's native file format is kind of a pain, and writing an Excel plugin is no fun either.

The easiest is probably CSV, but "XML Spreadsheet 2003" (XMLSS) is also pretty easy to read and supports more of Excel's formatting information.

Step 2 consists more-or-less of the following sub-steps:

2a. Open the file in Excel, then "Save As" using the file type drop-down "XML Spreadsheet 2003". If you want, you can permanently keep the Excel spreadsheet in this format for editing as well, but it only supports a subset of Excel's features. For simple data entry and calculations, it will work fine.
2b. Use a program that you've written to load the .xml file, read each worksheet, row, and cell.
2c. Convert the data however you need to.
2d. Save the converted data in a file that your game will load later.


You'll want to examine the XMLSS file by hand to familiarize yourself with the format, and then write a loader which can read the portions you care about. There are a bunch of sections you won't care about at all. It's fairly human readable. The spec is here in case you need it: http://msdn.microsoft.com/en-us/library/office/aa140066(v=office.10).aspx

Edited by Nypyren, 10 October 2013 - 07:38 PM.


#7 dejaime   Crossbones+   -  Reputation: 4119

Like
0Likes
Like

Posted 10 October 2013 - 08:48 PM

One important keyword for you, aside from the already mentioned by above posters, is hash table (hash map).

 

I was going to recommend an SQL library for C++ that was a single file, a single header to be precise, you could even copy and paste it on your program. But apparently I lost its name. I'll never forgive myself if I don't find its name...

 

You might find this interesting: http://www.boost.org/doc/libs/1_53_0/libs/serialization/doc/index.html


Edited by dejaime, 10 October 2013 - 08:54 PM.


#8 DekuTree64   Members   -  Reputation: 986

Like
1Likes
Like

Posted 11 October 2013 - 03:11 AM

I just make an enum of item ID values, a table of structs matching up to it where I enter data for each item, and then the player's inventory can be one of two styles:

 

a) The player can have at most 99 of each item, but can have 99 of every item in the game all at the same time (no inventory limit). The inventory is just an array of bytes that corresponds to the item ID enum, which tells how many of each item the player currently owns. When displaying the inventory, don't show any that are 0. Final Fantasy 6 does this style (although it lets you change the display order)

 

b) Each slot in the inventory is an item ID and number of how many. In this style you can carry more than 99 of the same item type, by having multiple bundles (e.g. 99 cure potions in one slot, 20 more in another slot). Most games that use this style have a fairly limited number of slots, so you often have to sell old weapons and armor to make room for new ones. Final Fantasy 4 does this style. Some games, such as Earthbound on SNES, only let you store one item in each slot. So if you have two cookies, it takes two slots. And you only have 20 slots or something total. Too frustrating, IMO.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS