• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
ChainedHollow

Using a database in a game or just multiple objects?

12 posts in this topic

I'm working on a game in SDL and C++ with RPG aspects, such as stats, and gear. What I am confused about is how to implement so many different types of gear with different stats. Such as , should each different type of item be a new object in the programming, or should is it somehow possible to create a database I can use and update at later times when I want to add new items to the game. I've also heard about scripting and XML but I am just not sure where to go with this. (I'm still pretty new to all this, all I've done so far is Blackjack, tetris, and pong.)

 

Basically I just need a way to describe an item. Give it a name, what type of clothing it is(head piece, gloves, etc.), and what stat changes it provides. Then in the game be able to grab the information and use it to alter the player's stats. 

 

If someone can point me in the right direction I'm sure I can figure out some way to implement this properly. 

This is my first original game idea and I'm still in the planning stages really. Thank you for any advice and help!

1

Share this post


Link to post
Share on other sites

Databases for games are a bit taboo unless you're talking like a dedicated server. Databases are just really bulky constructs designed for constant pulling and pushing of data like happens in an MMO or something, for a standalone game where you're just adding data you're not really going to be doing it on the fly so using just files would probably be best.

 

Keep in mind files are just data, if you're worried about simplicity of editing you can always design a tool for editing the files that mimicks what you would get from a database basically.

 

That said the above poster has some valid points, going file driven usually means writing up a fancy editor and data formats, it's -much- easier to put everything in code unless you're working on a team or something that needs immediate access to tweak data, or it's a particularly LARGE amount of items or something that you're editing on a regular basis.

0

Share this post


Link to post
Share on other sites

Basically I just need a way to describe an item. Give it a name, what type of clothing it is(head piece, gloves, etc.), and what stat changes it provides. Then in the game be able to grab the information and use it to alter the player's stats. 

 

Just use regular structures and enums.

Have one enum for type of the item : enum EObjectType {None=0, Weapon, Armour, Potion }

And have one struct that will keep all the relevant info about the item (whether it is a weapon, armour or potion):

struct SObject

{

  int ID; // global unique ID for the object - autoincrementing it, when filling up the internal DB is enough

  EObjectType ObjectType;

  .....

  int AddToStrength;

  int AddToDexterity;

  int AddToAccuracy;

  ...

  int RequiredStrength;

  int RequiredDexterity;

  int RequiredAccuracy;

}

 

Then, when using the item from the inventory, you just add those AddToStrength/Dexterity/Accuracy values to your stats values and you are done.

 

 

Personally, I am using text files for the database of the game objects. I wrote a very simple parser in an afternoon and never had to touch it since, so I guess it was a reasonable effort. This way, I can keep all my weapons, armours, potions in separate *.TXT files that are very easy to edit in Notepad.

 

When loading all items from the file, I just put them to a std::vector <SObject> Weapons, std::vector<SObject>Armour, std::vector<SObject> Potions. This way they are easy to work with (iterate, search, add/remove).

 

 

There is one more important advantage for having the "database" of items in TXT files - when you are testing, you will want to have multiple sets of these files so that you can test the different gameplay due to different objects/stats.

 

It will prove invaluable, when all the testers need to do, is just to replace the TXT files with a different set of TXT files. Even if that tester is just you.

Edited by VladR
0

Share this post


Link to post
Share on other sites
I would consider using JSON. There are a ton of parses available in dozens of languages, it's a simple format that solves many if the encoding files you could run into.

Think of JSON like a light weight ,vastly saner XML
1

Share this post


Link to post
Share on other sites

Use http://www.sqlite.org/

 

Anybody telling you that databases for games in any capacity are "too heavy" or "taboo" doesn't have experience writing real-world performance-critical applications reliant on volumes of data that need to be organized in a coherent manner.

 

SQL Lite is going to solve your problem.

-3

Share this post


Link to post
Share on other sites

Use http://www.sqlite.org/

 

Anybody telling you that databases for games in any capacity are "too heavy" or "taboo" doesn't have experience writing real-world performance-critical applications reliant on volumes of data that need to be organized in a coherent manner.

 

SQL Lite is going to solve your problem.

Just because it is possible, doesn't mean it is actually a good idea.

 

I do happen to have the experience you are talking about and that is exactly the reason why I would never even think about it.

 

That is, of course, unless you are being paid by an hour and your goal is to make it take as long to implement as possible, so that you could invoice more.

 

Which, I think, is not the case here with the OP...

0

Share this post


Link to post
Share on other sites

A database in the sense of a SQL Server installation or a MySQL installation would not only be massive overkill for your needs, but also wouldn't offer any compelling advantages over the simpler solutions in your case. I would take the approach recommended several times already and store all your item data in JSON text files. There are lots of great, simple parsers out there (such as picojson if you're using C++). A SQLite database may be a reasonable compromise between the two, but I still wouldn't recommend it in this case. It does not seem warranted.

0

Share this post


Link to post
Share on other sites

This is really funny.

 

We already spent more time arguing than it should take him to write a simple text parser smile.png

0

Share this post


Link to post
Share on other sites

Do the simplest thing that could possibly work. You will need some kind of serialisation if you intend to persist your stuff to disc.

 

You could use a third party serialisation library (boost is ok, I guess), or just write a really simple serialiser. It's up to you.

 

But don't make things more complicated than they need to be.

 

The use-case for a SQL database is mostly if you're storing a very large number of objects and don't want to keep them all in memory, but do want to use secondary indexes. Also interoperability.

 

If your database fits in memory, you plan to load it entirely in, and you don't want secondary indexing on-disc (if you don't know what this is, then you don't need it!) , then you probably don't need a SQL database.

 

Personally I'd probably write a really stupid serialiser that dumps things into text-files. Text files are really good because they're easy to debug.

0

Share this post


Link to post
Share on other sites

One thing I was really thinking about trying the next time I needed a lightweight persistence solution was to give Google's protocol buffers a shot.

 

It's pretty cool, example from wiki:

 

Message format:

message Point {
required int32 x = 1;
required int32 y = 2;
optional string label = 3;
}

message Line {
required Point start = 1;
required Point end = 2;
optional string label = 3;
}

message Polyline {
repeated Point point = 1;
optional string label = 2;
}

 

Then used in code:

 

#include "polyline.pb.h"  // generated by calling protoc polyline.proto (defined above)
 
Line* createNewLine(const std::string& name) {
  Line* line = new Line;
  line->mutable_start()->set_x(10);
  line->mutable_start()->set_y(20);
  line->mutable_end()->set_x(30);
  line->mutable_end()->set_y(40);
  line->set_label(name);
  return line;
}
 
Polyline* createNewPolyline() {
  Polyline* polyline = new Polyline;
  Point* point1 = polyline->add_point();
  point1->set_x(10);
  point1->set_y(10);
  Point* point2 = polyline->add_point();
  point2->set_x(10);
  point2->set_y(10);
  return polyline;
}
0

Share this post


Link to post
Share on other sites

I don't know if OP is still with us at this point anyway...

 

Basically I just need a way to describe an item. Give it a name, what type of clothing it is(head piece, gloves, etc.), and what stat changes it provides. Then in the game be able to grab the information and use it to alter the player's stats. 

 

If someone can point me in the right direction I'm sure I can figure out some way to implement this properly. 

There are two problems.

1st: a data structure must hold this data.

2nd: the data must get there.

While some people wrote about RDBMS (what?) an other about writing yet another domain specific language (c'mon), I'd rather consider the design problem first.

From your message, I have the impression you're considering examples... as a problem X instead of a problem Y. In generic terms. That's not the case. The first thing you must do is to sit down, and figure out what the game needs.

 

So, you have RPG elements. At the basic level say we deal about characters, stats and stat-boosting equipment.

An initial design might be (some fat trimmed and shortcuts taken)

struct Stat {
  String name;
  uint value;
  std::vector<StatModifier> effects;
  uint GetCurrentValue() const {
    uint ret = value;
    foreach(e : effects) ret += e.GetModifiers();
    return ret;
  }
};

class Character {
  std::vector<Stat> stat;
  Character() {
    stat.push_back(Stat(L"Strength", 10));
    stat.push_back(Stat(L"Hit points", 6));
  }
}

 

So, when equipping a pair of gloves giving STR+4 we look up for a "Strength" attrib and add a modifier.

Notice that an armor giving COS+20 would be wasted on a vampire as it has no "Constitution" attribute (not in D&D rule set at least).

You must resolve all the features you need to make your game work before starting to write. You don't need to figure them out in detail, but at least know in what direction you need to go.

For example, being copy-driven, the above method has an issue. If a specific object is disabled (say by enemy magic), what modifier do we need to change?

 

Notice at this point however, getting data there is rather straightforward. I suggest JSON to do that (it will take you a day). A JSON representation of the two objects above might be

gloves {
  "name" : "Empowering gloves"
  "attribEffects" : [
    { "str" : "4" }
  ]
}
armor {
  "name" : "Golem skin"
  "attribEffects" : [
    { "cos" : "20" }
  ]
}

 

I'm making this up right away so I cannot guarantee it will go through a proper JSON parser. But I'm confident it will, as JSON is so easy it will make you sick.

Now the problem is:

  • data to json: just iterate the various properties
  • json to data: more involved, must figure out the data structure to use, multiple data paths required.

I guess it's better to stop there now. This is a really open and complex problem, we could go on for ages.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0