if statement not working in this scenario?Dynamic network messagingBasic Server/Client Model built around...

Real life puzzle: Unknown alphabet or shorthand

What type of investment is best suited for a 1-year investment on a down payment?

If nine coins are tossed, what is the probability that the number of heads is even?

In iTunes 12 on macOS, how can I reset the skip count of a song?

Is there a frame of reference in which I was born before I was conceived?

Forward slip vs side slip

What type of postprocessing gives the effect of people standing out

The need of reserving one's ability in job interviews

Do higher etale homotopy groups of spectrum of a field always vanish?

Analog Mute Circuit - Simplest Solution

How do I deal with being jealous of my own players?

Can we carry rice to Japan?

How to substitute values from a list into a function?

What happened to QGIS 2.x

Dredging in a fantasy setting

What Does the Heart In Gyms Mean?

Wrap all numerics in JSON with quotes

Borrowing Characters

Graphing random points on the XY-plane

Is there any relevance to Thor getting his hair cut other than comedic value?

School performs periodic password audits. Is my password compromised?

How can I be pwned if I'm not registered on the compromised site?

lead or lag function to get several values, not just the nth

Inverse of the covariance matrix of a multivariate normal distribution



if statement not working in this scenario?


Dynamic network messagingBasic Server/Client Model built around ASIOUDP Server Design and PerformanceA socket server that receives strings and prints themRobust websocket server for use by a game running on nodeThorsSQL Lib: Part 3: Layer 5 HandShakeGame-oriented UDP protocolQueuing outgoing packets to fix server lag issuesEvent Based TCP LibraryDouble loop for input handling













-2












$begingroup$


I'm making a small networked game, still learning networking so I might be missing out on something.
I am using Visual Studio Community 2017.
I am using Allegro 5 for inputs and graphics.
I am using SDL_Net for networking.




  • The game is supposed to launch, works fine.

  • Every game tick, function HandleEvents(...) gets called in my code.

  • The game connects to the server if a mouse click was registered between 0-10 px on the screen, both x and y.


that worked fine, except that the client connected multiple times, so I set a condition so that it will only try and connect 1 client. I did this using a condition:



if(connected) {
std::cout << "Already connected.." << std::endl;
} else
...


Here's the actual code, so you can see what I have in the function.
function in MenuState.cpp:



void MenuState::HandleEvents(Input* input, ClientSocket* cs) {
if (input->mouseX >= 0 && input->mouseX <= 10 && input->mouseY >= 0 && input->mouseY <= 10) {
if (input->mouseB == MouseLDown) {
input->set_mouse_state(MouseNDown);

if (connected == true) {
std::cout << "You're already connected." << std::endl;
}
else if(connected == false) {
switch (cs->connectToServer()) {
case Packets::SERVER_NOT_RESOLVED:
break;
case Packets::SERVER_RESOLVED:
break;
case Packets::SERVER_DOWN:
break;
case Packets::SERVER_NOT_FULL:
{
connected = true;
std::cout << "Connected to server" << std::endl;
receivedMessage = "";

// Check if we've received a message
receivedMessage = cs->checkForIncomingMessages();

// If so then...
if (receivedMessage != "")
{
// Display the message and then blank it...
cs->displayMessage(receivedMessage);

// ...and then re-display the prompt along with any typed-but-not-yet-sent input
//cs->displayPrompt();
}

// Get and deal with input from the user in a non-blocking manner
cs->getUserInput();
}
break;
case Packets::SERVER_FULL:
break;
case Packets::SERVER_NO_RESPONSE:
break;
}
}
}
}
}


As you can see, there is clearly a condition check. The condition check works if I remove all networked code in case Packets::SERVER_NOT_FULL:










share|improve this question









$endgroup$

















    -2












    $begingroup$


    I'm making a small networked game, still learning networking so I might be missing out on something.
    I am using Visual Studio Community 2017.
    I am using Allegro 5 for inputs and graphics.
    I am using SDL_Net for networking.




    • The game is supposed to launch, works fine.

    • Every game tick, function HandleEvents(...) gets called in my code.

    • The game connects to the server if a mouse click was registered between 0-10 px on the screen, both x and y.


    that worked fine, except that the client connected multiple times, so I set a condition so that it will only try and connect 1 client. I did this using a condition:



    if(connected) {
    std::cout << "Already connected.." << std::endl;
    } else
    ...


    Here's the actual code, so you can see what I have in the function.
    function in MenuState.cpp:



    void MenuState::HandleEvents(Input* input, ClientSocket* cs) {
    if (input->mouseX >= 0 && input->mouseX <= 10 && input->mouseY >= 0 && input->mouseY <= 10) {
    if (input->mouseB == MouseLDown) {
    input->set_mouse_state(MouseNDown);

    if (connected == true) {
    std::cout << "You're already connected." << std::endl;
    }
    else if(connected == false) {
    switch (cs->connectToServer()) {
    case Packets::SERVER_NOT_RESOLVED:
    break;
    case Packets::SERVER_RESOLVED:
    break;
    case Packets::SERVER_DOWN:
    break;
    case Packets::SERVER_NOT_FULL:
    {
    connected = true;
    std::cout << "Connected to server" << std::endl;
    receivedMessage = "";

    // Check if we've received a message
    receivedMessage = cs->checkForIncomingMessages();

    // If so then...
    if (receivedMessage != "")
    {
    // Display the message and then blank it...
    cs->displayMessage(receivedMessage);

    // ...and then re-display the prompt along with any typed-but-not-yet-sent input
    //cs->displayPrompt();
    }

    // Get and deal with input from the user in a non-blocking manner
    cs->getUserInput();
    }
    break;
    case Packets::SERVER_FULL:
    break;
    case Packets::SERVER_NO_RESPONSE:
    break;
    }
    }
    }
    }
    }


    As you can see, there is clearly a condition check. The condition check works if I remove all networked code in case Packets::SERVER_NOT_FULL:










    share|improve this question









    $endgroup$















      -2












      -2








      -2





      $begingroup$


      I'm making a small networked game, still learning networking so I might be missing out on something.
      I am using Visual Studio Community 2017.
      I am using Allegro 5 for inputs and graphics.
      I am using SDL_Net for networking.




      • The game is supposed to launch, works fine.

      • Every game tick, function HandleEvents(...) gets called in my code.

      • The game connects to the server if a mouse click was registered between 0-10 px on the screen, both x and y.


      that worked fine, except that the client connected multiple times, so I set a condition so that it will only try and connect 1 client. I did this using a condition:



      if(connected) {
      std::cout << "Already connected.." << std::endl;
      } else
      ...


      Here's the actual code, so you can see what I have in the function.
      function in MenuState.cpp:



      void MenuState::HandleEvents(Input* input, ClientSocket* cs) {
      if (input->mouseX >= 0 && input->mouseX <= 10 && input->mouseY >= 0 && input->mouseY <= 10) {
      if (input->mouseB == MouseLDown) {
      input->set_mouse_state(MouseNDown);

      if (connected == true) {
      std::cout << "You're already connected." << std::endl;
      }
      else if(connected == false) {
      switch (cs->connectToServer()) {
      case Packets::SERVER_NOT_RESOLVED:
      break;
      case Packets::SERVER_RESOLVED:
      break;
      case Packets::SERVER_DOWN:
      break;
      case Packets::SERVER_NOT_FULL:
      {
      connected = true;
      std::cout << "Connected to server" << std::endl;
      receivedMessage = "";

      // Check if we've received a message
      receivedMessage = cs->checkForIncomingMessages();

      // If so then...
      if (receivedMessage != "")
      {
      // Display the message and then blank it...
      cs->displayMessage(receivedMessage);

      // ...and then re-display the prompt along with any typed-but-not-yet-sent input
      //cs->displayPrompt();
      }

      // Get and deal with input from the user in a non-blocking manner
      cs->getUserInput();
      }
      break;
      case Packets::SERVER_FULL:
      break;
      case Packets::SERVER_NO_RESPONSE:
      break;
      }
      }
      }
      }
      }


      As you can see, there is clearly a condition check. The condition check works if I remove all networked code in case Packets::SERVER_NOT_FULL:










      share|improve this question









      $endgroup$




      I'm making a small networked game, still learning networking so I might be missing out on something.
      I am using Visual Studio Community 2017.
      I am using Allegro 5 for inputs and graphics.
      I am using SDL_Net for networking.




      • The game is supposed to launch, works fine.

      • Every game tick, function HandleEvents(...) gets called in my code.

      • The game connects to the server if a mouse click was registered between 0-10 px on the screen, both x and y.


      that worked fine, except that the client connected multiple times, so I set a condition so that it will only try and connect 1 client. I did this using a condition:



      if(connected) {
      std::cout << "Already connected.." << std::endl;
      } else
      ...


      Here's the actual code, so you can see what I have in the function.
      function in MenuState.cpp:



      void MenuState::HandleEvents(Input* input, ClientSocket* cs) {
      if (input->mouseX >= 0 && input->mouseX <= 10 && input->mouseY >= 0 && input->mouseY <= 10) {
      if (input->mouseB == MouseLDown) {
      input->set_mouse_state(MouseNDown);

      if (connected == true) {
      std::cout << "You're already connected." << std::endl;
      }
      else if(connected == false) {
      switch (cs->connectToServer()) {
      case Packets::SERVER_NOT_RESOLVED:
      break;
      case Packets::SERVER_RESOLVED:
      break;
      case Packets::SERVER_DOWN:
      break;
      case Packets::SERVER_NOT_FULL:
      {
      connected = true;
      std::cout << "Connected to server" << std::endl;
      receivedMessage = "";

      // Check if we've received a message
      receivedMessage = cs->checkForIncomingMessages();

      // If so then...
      if (receivedMessage != "")
      {
      // Display the message and then blank it...
      cs->displayMessage(receivedMessage);

      // ...and then re-display the prompt along with any typed-but-not-yet-sent input
      //cs->displayPrompt();
      }

      // Get and deal with input from the user in a non-blocking manner
      cs->getUserInput();
      }
      break;
      case Packets::SERVER_FULL:
      break;
      case Packets::SERVER_NO_RESPONSE:
      break;
      }
      }
      }
      }
      }


      As you can see, there is clearly a condition check. The condition check works if I remove all networked code in case Packets::SERVER_NOT_FULL:







      c++ networking socket sdl allegro






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 20 mins ago









      Matias PerssonMatias Persson

      223




      223






















          0






          active

          oldest

          votes











          Your Answer





          StackExchange.ifUsing("editor", function () {
          return StackExchange.using("mathjaxEditing", function () {
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          });
          });
          }, "mathjax-editing");

          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "196"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f214803%2fif-statement-not-working-in-this-scenario%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Code Review Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f214803%2fif-statement-not-working-in-this-scenario%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Webac Holding Inhaltsverzeichnis Geschichte | Organisationsstruktur | Tochterfirmen |...

          What's the meaning of a knight fighting a snail in medieval book illustrations?What is the meaning of a glove...

          Salamanca Inhaltsverzeichnis Lage und Klima | Bevölkerungsentwicklung | Geschichte | Kultur und...