title: How to set up a notification system in a game
body: <p>I'm working on a 3D learning-based game which mainly utilizes C++ and Javascript. I'm trying to design a notification system for when the player has information sent to their notebook.</p>
  
  <p>I had a system set up, but the supervisor thinks it can be made better. This is where I need y'alls help!</p>
  
  <p>The very basic way it went:</p>
  
  <p>The player would do something that triggered information to be sent to the notebook. In the same method where this happened, I turned on the notification. The notification would then show up on the player's screen by flashing two div's of an image (making a blinking effect). When either one of these divs is clicked, it shows the player the notebook. Anytime the player views or exits the notebook, the notification is turned off.</p>
  
  <p>Now here is the code I was using:</p>
  
  <p>In the main GameState</p>
  
  <pre><code>int GameModeState::notify(int query)
  {
      static int notified;
      if(query == 1)
      {
          notified = 1;
          return notified;
      }
      if(query == 2)
      {
          notified = 0;
          return notified;
      }
      else
      {
          return notified;
      }
  }
  </code></pre>
  
  <p>In the GameState's update function</p>
  
  <pre><code>// checks if the unviewed information notification needs to be on or off
  if(notify(0) == 1) // supposed to be on
  {
      mScreen-&gt;executeJavascript("notebookNotification(1);"); // turns it on
  } else {
      int nothing = notify(2); // clears out notify to 0
      mScreen-&gt;executeJavascript("notebookNotification(0);"); // turns it off
  }
  </code></pre>
  
  <p>In my JS</p>
  
  <pre><code>var intervalID; // Needed to turn off setInterval()
  //Function takes in 0 to turn off notification, anything else turns it on
  function notebookNotification(setting)
  {
     if(setting == 0)
     {
        if(intervalID) {
          // clears the blinking darkContainer
          window.clearInterval(intervalID);
          intervalID = null;
      }
      // hides both of the images
      $("#lightNotificationContainer").hide();
      $("#darkNotificationContainer").hide();
  }
  else
  {
      $("#lightNotificationContainer").show();
      if(!intervalID) {
          // "animates" the blinking of the notification; the darkContainer toggles on and off every second, and covers the lightContainer
          intervalID = window.setInterval('$("#darkNotificationContainer").toggle()', 1000);
      }
  }
  }
  </code></pre>
  
  <p>I would turn off the notification using <code>GameModeState::notify(2)</code></p>
  
  <p>Now, what would be a better system to use rather than this?</p>