Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

How do I make it so that in a multiple-level game the score will stay where it was from the previous level?

share|improve this question

Store the score outside of the level, probably in the game object that manages which level you are on:

class Game {
  int score;
  Level * currentLevel;

If there is code within a given level object that might need to manipulate the score, you can pass that information to the level when it is constructed. You could simply pass a pointer to the score integer (the simplest, most straightforward option) or you could encapsulate the score in its own interface:

struct Score {
  int GetCurrentPoints () const;
  void AddPoints (int points);

struct Level {
  Level (Score * globalScore)
  : score(globalScore) {

  Score * score;

class Game {
  Score score;
  Level * currentLevel;

Pass the a pointer to the game's instance of the single global score to each level, which they store and manipulate, and it will persist across levels as you'd like.

share|improve this answer

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.