Coding Help! - Driving Speed toggle wont work

Hi, I am trying to make a button (B) that when pressed will toggle slow drive speed on and off. I was able to get this to work in another program, but when I copied over the working code, it doesn’t work. I’ve rewritten the code multiple times, and everyone that I’ve shown it to has said that it should be working. We are honestly not sure how to fix this, so if anyone knows what’s wrong I would love to hear it.

You are setting your variable values inside your void usercontrol function, and those are constantly getting reset to those values when usercontrol is running. You want to set those initial values outside of the usercontrol function.

move the event registration outside of the while loop. events should only be registered once.
all the lines like this.

    //DRIVE SPEED TOGGLE
    Controller1.ButtonB.pressed(bPressed);

I would probably set them here.

//
// Main will set up the competition functions and callbacks.
//
int main() {
  // Set up callbacks for autonomous and driver control periods.
  Competition.autonomous(autonomous);
  Competition.drivercontrol(usercontrol);

  //DRIVE SPEED TOGGLE
  Controller1.ButtonB.pressed(bPressed);
  //DRIVE DIR TOGGLE
  Controller1.ButtonX.pressed(xPressed);
  //INTAKES
  Controller1.ButtonA.pressed(aPressed);
  Controller1.ButtonY.pressed(yPressed);

  // Run the pre-autonomous function.
  pre_auton();

  // Prevent main from exiting with an infinite loop.
  while (true) {
    wait(100, msec);
  }
}

or in pre-auton function, same thing really.