VCS C++ Toggle Code Help

Hello! I’ve been attempting to code a toggle sequence for a motor on my robot named Intake in the code below. I came up with the following solution, and although I understand it might be a bit needlessly complicated, I don’t see any reason why it shouldn’t work. Any sort of advice or fix would be very helpful!

For the curious:
Whenever I press the button, the motor does not spin at all
The motor worked perfectly fine when I activated it through other means, so the motor/wire/port is not defective
I added a line later just before the second if statement that prints the value of intakeInt and tempintakeInt to the brain, and intakeInt was 1, while tempintakeInt was 0(???)

–CODE START–

int intakeInt = 0, tempintakeInt = 0;

void IntakeSequence(){
tempintakeInt = 0;
if ((intakeInt + tempintakeInt) == 0){
Intake.spin(vex::directionType::fwd, 100, vex::velocityUnits::pct);
intakeInt = 1;
tempintakeInt = 1;
}
if ((intakeInt + tempintakeInt) == 1){
Intake.spin(vex::directionType::fwd, 0, vex::velocityUnits::pct);
intakeInt = 0;
}
}

int main()
{
while (true)
{
Controller1.ButtonL2.pressed(IntakeSequence); //rest of dc omitted for your convenience
}

}

–CODE END–

Thanks for reading through this!

the pressed command only works if you put it above the while loop. I have no idea why. Also I do not see the need for two variables. Try something like this:

int intakeCount = 0;
void intakeSequence(){
       intakeCount++;
       if((intakeCount % 2) == 1){
              Intake.spin(vex::directionType::fwd, 100, vex::velocityUnits::pct);
       }
       else{
              Intake.spin(vex::directionType::fwd, 0, vex::velocityUnits::pct);
       }
}

int main(){
       Controller1.ButtonL2.pressed(IntakeSequence);
       while(true){
              
       }
}

Thanks! Worked like a charm.