V5 Coding help needed.

Whats wrong with this code??? Its a puncher code and what I want it to do is when I press Button X, the puncher motors turn 270 degrees and shoots and stops.

int puncher(int)
{
    while(true)
    {
      Punchermotor1.startRotateTo(270,vex::rotationUnits::deg,100,vex::velocityUnits::pct);
      Punchermotor2.startRotateTo(270,vex::rotationUnits::deg,100,vex::velocityUnits::pct);
      
      Punchermotor1.stop(vex::brakeType::brake);
      Punchermotor2.stop(vex::brakeType::brake);
    }   
}

void usercontrol( void ) {
  // User control code here, inside the loop
  while (1) 
  {
    // This is the main execution loop for the user control program.
    // Each time through the loop your program should update motor + servo 
    // values based on feedback from the joysticks.

    // ........................................................................
    // Insert user code here. This is where you use the joystick values to 
    // update your motors, etc.
    // ........................................................................
    if(Controller.ButtonX.pressed(int (puncher(int)));
    }
}

And second question: What is the difference between “rotateTo”, “startrotateTo”, “RotateFor” and “startRotateFor”?

Last question (I swear): Are there any sample codes (not the ones on VCS) that I can see to understand VCS and C++? It is very challenging for me to code in VCS and am struggling very hard.

Desperately thanks,
2979E.

.pressed isn’t what you think it is. It starts up a thread that looks for the button to be pressed, and when it’s pressed it calls whatever function you gave it. If you look up “event handlers,” it should help. So right now you’re trying to set up an infinite number of event handlers that do the same thing.

You’re also not declaring your function properly. You would need “int something” where “something” is the name the function is using for an int. But you need void when used here anyway.

Are you sure you don’t want “hold” instead of “brake” with a puncher?

Finally, you have it forever rotating to 270 and stopping instead of doing it once.

Look at this version of what you posted:

void puncher(void)
{
      Punchermotor1.startRotateTo(270,vex::rotationUnits::deg,100,vex::velocityUnits::pct);
      Punchermotor2.RotateTo(270,vex::rotationUnits::deg,100,vex::velocityUnits::pct);
      Punchermotor1.stop(vex::brakeType::hold);
      Punchermotor2.stop(vex::brakeType::hold);
}

void usercontrol( void ) {
  
   Controller.ButtonX.pressed(puncher);

  while (1) 
  {
    // whatever you're doing here
    }
}

Thanks @callen.