2
\$\begingroup\$

Recently I started working on a Web turn-based PvP RPG game. Now I'm working on the battle system but I encountered some issues:

How can I keep track of everything that happens in the battle? It should keep track of the characters on the field, inventory, the damage done etc.

I first thought I would simply put it in the (MySQL) database, but I think it will be too much. Especially if several people are in a battle. I thought of puting this in sessions or cookies but I don't think thats reliable.

Does anyone have an idea how I can do this?

\$\endgroup\$
1
  • \$\begingroup\$ Is this a play-by-mail style game? How long do you need to store the "condition" of the battle field and how often does it change? \$\endgroup\$ Jun 17, 2012 at 23:12

1 Answer 1

6
\$\begingroup\$

I first thought I would simply put it in the (MySQL) database

Sounds good!

but I think it will be too much.

Then you don't know the limits yet.

Seriously, just throw everything in a database. Don't care about performance too much at this stage, if it becomes an issue you can fix it later.

Here's an abstract view of what your database could look like:

Character
-- id (int, key)
-- name (string)
-- health (int)

InventoryItem
-- id (int, key)
-- character_id (int)
-- name (string)

Battle
-- id (int, key)
-- name (string)
-- location_id (int)

BattleParticipants
-- id (int, key)
-- battle_id (int)
-- character_id (int)

This employs something called database normalization, where each unique piece of data is stored once and only once.

Now, if you want to get the names of the participants in a battle, you can use an inner join to combine the data tables. This should explain that:

http://www.codinghorror.com/blog/2007/10/a-visual-explanation-of-sql-joins.html

\$\endgroup\$
2
  • \$\begingroup\$ This is great advice, +1 \$\endgroup\$
    – Jumbala
    Jun 18, 2012 at 7:22
  • \$\begingroup\$ Hey this is truely great advice! Luckily I know my way around with SQL! Thanks a lot! \$\endgroup\$
    – Jay Wit
    Jun 18, 2012 at 9:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .