Multiple choice game

A

Answers

  • Use mousePressed() (the function) instead of mousePressed (the boolean). The function runs once per click.

  • I think I altered my code correctly and I still get a similar issure

  • It is impossible to tell without seeing the altered code.

  • edited May 2018

    Here it is:

  • edited April 2018 Answer ✓

    First thing first: REMOVE ALL CALLS TO delay().

    The delay() function does not do what you think it does. It is not the function you want. It is not useful in this context. Do not use it at all.

    Next, look at the structure of your mousePressed function:

    void mousepressed(){
      // This block runs only if scene is 0.
      if( scene == 0 ){
        // Maybe go to a difference scene.
      }
      // This next block runs if scene is 1.
      // What if scene was 0, the above block ran, and it changed to 1?
      if( scene == 1 ){
        // Pick a weapon.
      }
    }
    

    Now consider this small change:

    void mousepressed(){
      // This block runs only if scene is 0.
      if( scene == 0 ){
        // Maybe go to a difference scene.
      }
      // This next block runs if scene is 1, and the above block didn't run.
      else if( scene == 1 ){
        // Pick a weapon.
      }
    }
    

    Notice the else keyword. This makes it so that only one block runs, and so changing the scene in the first one won't immediately cause the second one to run too if its conditions are met.

  • ah yes!, that made it work. Thanks for the help! i'll probably be back in a bit when i break it again :))

Sign In or Register to comment.