-1

I've a switch and a functions 'block the case that are after it' at the 4th case of the switch.

I tried to move the case and apparently it's the 'P_JEU' case that block but I don't understand why.

switch (partie) {

    case P_CHOIX_ANIM:
      allPlayers.chenillard(250,100);
      partie = P_CHOIX;

    case P_CHOIX:
      temp = allPlayers.checkInterro();
      if (temp == 0) break;
      if (temp == 1) { //Only 1 press
          partie = P_JEU;
          DEBUG_PRINTLN("P_CHOIX 1 press");
          break;
      }
      partie = P_CHOIX_ERREUR;
      break;

    case P_JEU:
      // Bug
      if (bConfig.isPressed()) {
        if (bConfig.getPressDuration()) {
          if (bConfig.getPressDuration() <= 2000) {
            partie = P_CHOIX_RESET;
          } else {
            bConfig.reset();
          }
        }
      }
      allPlayers.filteredCall(A_CHECK, J_PLAYER);
      bool passResponse = allPlayers.Pass();
      if (passResponse) { partie = P_JEU_REPONSE; }
      break;

    case P_CHOIX_RESET:
      allPlayers.reset();
      bConfig.reset();
      partie = P_CHOIX_ANIM;
      break;

    default:
      DEBUG_PRINTLN("Default");
      partie = P_CHOIX_RESET;
      break;

Thanks

gre_gor
  • 6,669
  • 9
  • 47
  • 52
Arthur
  • 44
  • 6

1 Answers1

-1

You cant declare variables inside a case: https://complete-concrete-concise.com/programming/c/keyword-switch-case-default/ Can I declare variables inside an Objective-C switch statement?

bool passResponse = allPlayers.Pass();

is wrong - you have to enclose it:

case P_JEU:
      // Bug
      if (bConfig.isPressed()) {
        if (bConfig.getPressDuration()) {
          if (bConfig.getPressDuration() <= 2000) {
            partie = P_CHOIX_RESET;
          } else {
            bConfig.reset();
          }
        }
      }
      allPlayers.filteredCall(A_CHECK, J_PLAYER);
      {
          bool passResponse = allPlayers.Pass();
          if (passResponse) { partie = P_JEU_REPONSE; }
      }
      break;
Wolfgang
  • 320
  • 3
  • 12
  • Thanks a lot, it's effectly the problem – Arthur May 19 '20 at 09:42
  • This answer is wrong. C permits declarations inside `switch` statements, just not immediately after a `case` label. There can be scope issues from that. Although OP accepted the answer, there must be some other issue. Additionally, the links given in this answer are bad. The first does not mention declarations and wrongly says the controlling expression is converted (not just promoted) to `int` and can be a floating-point type, and the second is not for C. – Eric Postpischil May 19 '20 at 09:52
  • What does an Objective-C reference have to do with anything here? Remove. – TomServo May 20 '20 at 00:52
  • TomServo, you should at least read the linked post (and the answers) before you post a comment here. There you can read about C. If I was wrong with the answer, that's one thing - it simply jumped into my eye. But just commenting without giving a real, alternative solution is another. – Wolfgang May 26 '20 at 05:43