Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am looking to track many in-game events, e.g. the score of each move, how many moves are taken, what types of moves, etc. A lot of stats can simply be tracked with a counter. In some cases I need to aggregate data in order to calculate the value (e.g. most common move). How are you tracking in-game stats for your games? How do you avoid creating a class with tens or hundreds of fields? How do you avoid littering the code with tracking invocations? How do you abstract the aggregate data so as to avoid rewriting it for each scenario?

share|improve this question
up vote 5 down vote accepted

The way I usually end up doing it is to first use a messaging system. Let's say that you send a message each time the player fires his weapon. Then, the weapon system (or the weapon object) acts on that message when it is received and the weapon is fired. If you then want to keep stats of when a weapon is fired, simply log the messages to a list somewhere. Then it would be easy to go from that list and generate statistics from that.

You could consider introducing an object that has the sole responsibility for tracking game stats. It could simply listen to all the relevant messages, and append them to their respective lists

share|improve this answer
+1 This is a nice solution. I would say "definitely introduce an object" instead of "you could consider", though. – Marton Nov 20 '12 at 11:54
Thanks for your suggestion, I ended up implementing a messaging queue and have various publishers and subscribers working with it. – Alex Schearer Nov 21 '12 at 12:19

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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