Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6093341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:32:55+00:00 2026-05-23T12:32:55+00:00

I’m working on a 3D learning-based game which mainly utilizes C++ and Javascript. I’m

  • 0

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.

I had a system set up, but the supervisor thinks it can be made better. This is where I need y’alls help!

The very basic way it went:

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.

Now here is the code I was using:

In the main GameState

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;
    }
}

In the GameState’s update function

// checks if the unviewed information notification needs to be on or off
if(notify(0) == 1) // supposed to be on
{
    mScreen->executeJavascript("notebookNotification(1);"); // turns it on
} else {
    int nothing = notify(2); // clears out notify to 0
    mScreen->executeJavascript("notebookNotification(0);"); // turns it off
}

In my JS

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);
    }
}
}

I would turn off the notification using GameModeState::notify(2)

Now, what would be a better system to use rather than this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:32:55+00:00Added an answer on May 23, 2026 at 12:32 pm

    Algorithm Improvements

    • Don’t use a static flag. Create an id system so that you can uniquely target a notification.
      • In C++ you could keep track of a variable that auto-increments whenever you make a new notification. The id could be #notification_# where # is the id you want. Then your notify function will send the id it wants to stop/start, as well as the parameter to start or stop it.
      • In JavaScript, you then embed the id from the creation of the interval in the tag. I’d recommend using .data(). That way you can turn it off.

    JS Improvements (not much better, really)

    • Use ===/!== istead of ==/!= in most cases. Also avoid truthy stuff if you can be more specific.
    • Combined the hide notification into one query.

    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 !== null) {
                // clears the blinking darkContainer
                window.clearInterval(intervalID);
                intervalID = null;
            }
            // hides both of the images
            $("#lightNotificationContainer,#darkNotificationContainer").hide();
        }
        else {
            $("#lightNotificationContainer").show();
            if (intervalID === null) {
                // "animates" the blinking of the notification; the darkContainer toggles on and off every second, and covers the lightContainer
                intervalID = window.setInterval('$("#darkNotificationContainer").toggle()', 1000);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace
I am trying to loop through a bunch of documents I have to put
I have a text area in my form which accepts all possible characters from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.