I am playing Starcraft2 and I am fascinated of how it is engineered. So lets say you played a 1v1 ranked game and you pumped 10 marines in the first 320 seconds. You'll get an achievement for that. I was wondering how is the achievements system designed underneath? Yes it analyzes the replay file which is frame based, but how? There are 1000 achievements now.

  • \$\begingroup\$ I doubt it analyzes the replay file. It probably just keeps track of achievements on the fly. \$\endgroup\$
    – Evorlor
    Dec 30, 2015 at 19:53

1 Answer 1


Achievement systems are actually pretty simple.

They can be built in any number of ways, but they revolve around two things:

  1. Statistics tracking
    • Every time a thing happens, a notification (event, a method call, or other notification type) is sent off to the statistics tracking object saying "this thing happened." e.g. When you build a marine, the statistics tracker adds 1 to the numMarinesBuilt value
    • Singleton or a static class is sufficient for a single player game, for multiplayer you'd need an instance per player
  2. Statistics comparison
    • Then the altered statistic is compared against a threshold value of some kind, and if all checks pass, the achievement is awarded. e.g. if(Achievements.marines320.isNotAwarded() && numMarinesBuilt > 10 && curGameTime < 320) { //award achievement }

Both happen in the same method, usually. Some achievements like "win a game never having destroyed an outpost" have the logic split up: destroying an outpost sets a flag to true ("we did this thing at least once"), then when the game ends and the win logic is checked, the statistics comparison is made to check to see that that flag is still false ("if we did not do the thing: achievement").

Receiving the achievement would then fire off its own notificaiton to a central handler that would result in the popup saying "Yay you did Thing!" with a picture icon and some text on a GUI object background. If using SteamworksAPI (or similar) you'd also inform the API of the achievement as well.

  • \$\begingroup\$ This is a good explanation of how you'd hardcode something like this, but I think the OP would do better with an explanation of how it's handled from a non-developer standpoint. Keep in mind that the achievement system is handled by game designers, not programmers, in most cases, so most achievement systems would have to be designed as a tool that could be used by game designers (i.e. non programmers) to setup the conditions for an achievement. \$\endgroup\$
    – stix
    Dec 30, 2015 at 16:52
  • \$\begingroup\$ Do you mean in terms of "what makes a good statistic?" And "what level of a statistic makes a good achievement?" That gets very opinion based very quickly, which is considered off-topic. \$\endgroup\$ Dec 30, 2015 at 17:24
  • \$\begingroup\$ I think they mean that the code/achievement are not hardcoded but in some sort of language. To develop that there would be in two parts, statistics would be hardcoded. Updated statistics trigger some kind of bytecode like interpreter. This could happen in a separate thread. gameprogrammingpatterns.com/bytecode.html \$\endgroup\$
    – Felsir
    Dec 30, 2015 at 17:35
  • \$\begingroup\$ Its possible. I didn't get that from the asker's post, however. \$\endgroup\$ Dec 30, 2015 at 17:45
  • \$\begingroup\$ Me neither, that's why I added it as comment not a more elaborate answer. Upvoted your answer as it answers the posted question. \$\endgroup\$
    – Felsir
    Dec 30, 2015 at 18:27

You must log in to answer this question.

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