# How can I keep track of a battle log on a web game?

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?

• 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? – chaosTechnician Jun 17 '12 at 23:12

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

• This is great advice, +1 – Adam Smith Jun 18 '12 at 7:22
• Hey this is truely great advice! Luckily I know my way around with SQL! Thanks a lot! – Jay Wit Jun 18 '12 at 9:30