0
\$\begingroup\$

I'm working on a online game but, what would be the best way to store values like damage,movespeed,turnrate, and so on.. ?

My answer would be, to store them in a Database, so they can easily be changed by any developer and are "unreachable" for the useres, or are there better ways to do that?

\$\endgroup\$
  • 1
    \$\begingroup\$ Damage, movespeed, turnrate and so on of what? Players? Mobs? Are they static for each type of object or can they change for individual instances of players/mobs? When the latter: Is it even useful to persist them then? \$\endgroup\$ – Philipp Aug 13 '14 at 9:13
  • \$\begingroup\$ of everything. storing them somewhere else makes it much easier to change them for new "patches". example: if a dmg of a mob/skill/player is too high, you would like to change them. Maybe the people who are responsible to make the game balanced (game designer or other) have no programming skillz, therefore it would be great for them. In offline Games I often see them stored in a txt file. But for an online game i'm not sure about this \$\endgroup\$ – jeromintus Aug 13 '14 at 11:16
  • \$\begingroup\$ When an individual player becomes to powerful, the maintainers edit that one player-character and make it weaker? Is that really what you mean? I think you aren't talking about the character stats themself but rather about the rules which apply to all player-characters and from which the actual stats are derived. \$\endgroup\$ – Philipp Aug 13 '14 at 11:37
  • \$\begingroup\$ To clarify: There are two kinds of data in a game. Dynamic data which changes through gameplay ("The player-character Bob the Barbarian is level 43 and has 1276 gold") and master data which is preconfigured by the admins ("Sword of Awesomeness has +12 attack"). Are you talking about master data or dynamic data? Because these usually need to be handled differently. \$\endgroup\$ – Philipp Aug 13 '14 at 11:41
  • \$\begingroup\$ for balancing, Skills are a better example, which most likely need to be changed. lvl42 and gold should be stored anyway in a database, i think \$\endgroup\$ – jeromintus Aug 13 '14 at 11:43
1
\$\begingroup\$

There are different options to consider. Which one you pick depends on your requirements and preference.

Hardcoded values

You just put all the values right into your sourcecode.

This is the easiest solution for the programmer because no code is needed to read these values from a file or database. Unfortunately it is a real maintainance nightmare, because only a programmer can change the values and each change requires to recompile the binary.

This solution is only recommendable for very small games or during the prototyping stage.

Put the values in a file

You store the values in one or more file in JSON, XML, CSV or some other format. When the server starts, it reads the file and loads all the values from it. When you do it well, you can even design your server in a way that it can reload and apply the files without having to restart.

Maintainers can then edit these files with any text editor without having to change the sourcecode. You also have the option to develop a GUI-based tool to edit these files, when you feel that it is worth the effort.

Another advantage of files is that any files which are needed by both the server and the client can be easily shared between server and clients through your usual asset distribution process.

Put the values in a database

You need a database anyway for storing all your dynamic data, so putting your static data there seems like an obvious solution.

The advantage is that databases are built for having multiple users work with them at the same time. That means your maintainers can work in parallel without edit conflicts. When you would use files, multiple users would not be able to edit the same file at the same time.

However, there are some drawbacks to databases: Editing a live SQL database (or some noSQL solution, when you swing that way) can not be done with a text editor. Your maintainers either need to know SQL (which is a really inconvenient way to do data entry) or they need a GUI tool. There are general-purpose GUI tools available for SQL databases which make this a bit more convenient than a SQL shell, but are still not as intuitive as a simple text editor. That means you likely won't get around writing your own GUI tool for maintaining your data.

Another drawback of databases is that they usually can not be versioned. A text file can be put under version control, so you have a change history. But with a SQL database, you can't do this. You would have to implement your own versioning feature in your GUI application.

\$\endgroup\$
  • \$\begingroup\$ I think, a database is the best way to go. Another Option would maybe be Scripting/Visual Scripts Right now, my data damgae for a skill, is changeable for non-programmers via a visual script inside my Engine(UE4) It would be great to know how games like Dota2,WoW handle these things. Because they change damge etc. with patches, and if I would do it with a database I wouldn't need a patch(i think) \$\endgroup\$ – jeromintus Aug 13 '14 at 12:01
  • \$\begingroup\$ They don't necessarily change the damage with patches. They do a lot of work, bug fixes? new features and tweaks. They also change some values to balance the game (nerfing / buffing) and so forth. Then they playest everything and release it. I don't think that means the values are embedded in the code. Besides it's unlikely that an optimized game with a lot of users will send you the values for each attack and weapon statistics every time you login, so it's far more likely they have a DB that generates an XML or what not. Then they only send the XML once. \$\endgroup\$ – AturSams Oct 12 '14 at 16:20
1
\$\begingroup\$

I personally think these values are best stored inside a text file in plain text. There is nothing easier to read an edit. Each class (game character class like Fighter, Mage and so) could have it's own text file and every monster as well. It keeps things manageable and accessible to none programmers. JSON is great until a confused none programmer erases a { by accident or misses a ' that is needed for a string.

A plain text with comments like this:

# Fighter class configuration
name: Fighter
# This affects damage output
attack: 12
.
.
.
\$\endgroup\$
  • \$\begingroup\$ Its not really plain text then, is it? regardless +1 for suggesting that a simple solution might be best. \$\endgroup\$ – Textmode Nov 12 '14 at 10:02
  • \$\begingroup\$ @Textmode You mean it's not plain because it uses a format that could be parsed later? Well, it's as plain as it gets imho. You could use a JSON if you need flexibility and wish to store arrays for some reason. (like a list of powers for a specific level or what not) \$\endgroup\$ – AturSams Nov 12 '14 at 14:15

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