-1

I have been Stumped, I'm using the Eclipse IDE and am building a game using ATW and Swing. however, a random bug snuck its way into my script and I don't know how or why as this part of the code has not been touched in ages. Essentially I am using a switch statement to determine which images are to be loaded at what time to create a sort of intro sequence, Here is the script:


        // condition that only runs once within the print function

        if (gameState == "start")
        {
            //gameAudio.loopMusic(false);




            //intro animation
            switch(startCounter) 
            {
                //3 and a half seconds of buffer split into 10 parts to allow for updating screen during startup of app
              case 0:
              case 1:
              case 2:
              case 3:
              case 4:
              case 5:
              case 6:
              case 7:
              case 8:
              case 9:
                wait(350);

                break;

              case 10:  
                gameAudio.playMusic("src/res/audio/JackEditedIntro.wav");
                gameAudio.setVolume(0.6);
                wait(300);
                samIcon = new ImageIcon("src/res/SamAssets/SamFullBody/SwingUpSam.png");

                break;

              case 11:
                  wait(40);
                  samIcon = new ImageIcon("src/res/SamAssets/SamFullBody/HighFiveSam.png");
                  samPow = new ImageIcon("src/res/SamAssets/SamFullBody/PowSam.png");

                  break;

              case 12:
                  wait(100);
                  samIcon = new ImageIcon("src/res/SamAssets/SamFullBody/HighFiveSam.png");
                  samPow = new ImageIcon("");

                  break;


              case 13:
                  wait(1200);
                  samIcon = new ImageIcon("src/res/SamAssets/SamFullBody/WaveSam.png");

                  break;
              case 14:
                  wait(1200);
                  samIcon = new ImageIcon("src/res/SamAssets/SamFullBody/SwingUpSam.png");

                  break;

              case 15:
                  wait(40);
                  samIcon = new ImageIcon("src/res/SamAssets/SamFullBody/IdleSam.png");

                  break;

              case 16:

                  wait(500);
                  samIcon = new ImageIcon("");

                  break;

              case 17:

                  wait(300);
                  gameAudio.playMusic("src/res/audio/BattleStart.wav");

                  wait(2000);

                  break;

              default:
               wait(5);
               System.out.println("Default start up switch statement");
            }



            setBackground(Color.BLACK);
            samIcon.paintIcon(this,  g,  540, 20);
            samPow.paintIcon(this, g, 720, 20);



            //samIcon.ImageIcon();









            if (startCounter < 17)
            {
                startCounter += 1;


            }


            else
            {
                //start the actual game
                gameState = "menu";

                //play the song

                gameAudio.playMusic("src/res/audio/AllTheWay.wav");
                gameAudio.setVolume(0.2);
                gameAudio.loopMusic(true);


                // default Sam
                samIcon = new ImageIcon("src/res/SamAssets/IdleSam.png");

            }


        }

The Issue is that not all of my images are being loaded and some sound files are not playing (I quintuple checked the source files which, again, have not been touched for ages and should not be part of the problem). The script appears to be skipping case 11, case 13, case 15 and case 17 so my best guess would be that the script is skipping every second case condition (hard for me to verify if it is skipping in the earlier parts of the statement), but i haven't the faintest as to why. If anyone could shine some light on my issue I would greatly appreciate it.

PS: This is only my second huge coding project in my entire life and so I deeply apologize for the damningly terrifying coding style and hope you can forgive me, thank you.

Update: I added a System.out.println to every case incrementation and every number is appearing in the console despite the images and audio not being loaded in those same cases. Consider me 200% more confused, I desperately need help.

  • `if(gameState == "start")` [is the wrong way of comparing strings](https://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java), if the if block is being entered at all. – ernest_k May 23 '20 at 01:23
  • ah yes, that's a good note. I changed it to: gameState.equals("start") and it didn't seem to fix the issue. Thank you for the recommendation though! – NovaDorium May 23 '20 at 01:50
  • I'm not sure what "I added a System.out.println to every case incrementation" means. How about you show exactly what your code is now, with blank lines removed, and the exact output that you see? – David M. Karr May 28 '20 at 02:47

1 Answers1

-1

do you stay in a conditional "while" and any moments you variable implements +1, and i your logic there is a condition that implement +1. Please remove it:

if (startCounter < 17)
            {
                startCounter += 1;


            }

or review this logic, because in any moment do you sum plus 1.

Rafael Rfs
  • 1
  • 1
  • 1
  • Hi, thanks for the comment. I did a word search for my variable and the only time that the variable is changed is within that if statement... unfortunately I don't think that is the culprit in my script – NovaDorium May 23 '20 at 01:52
  • Please share whole script man – Rafael Rfs May 23 '20 at 16:58