Programming the voids

Hello!
We’re having a bit of trouble programming because it’s our first time doing this competition and we are new to programming. We would like to know what to write in between the 2 “voids” when we put in the command for “pressed”. On the VCS Command Reference, it says to add a function, but we don’t know what a function is

You would need to set up a function and then call it. However, that may not be what you are looking for. If you want a simple control for say, moving a motor when a button is pressed, use something like this:

int main(){
if(Controller1.whateverbutton.pressing()){
       motor.spin(directionType::fwd, 100, vex::velocityUnits::pct);
}
else{
      motor.stop(brakeType::coast);
        }
}

If you wanted to actually have a function go until completion, then you need to set it up beforehand. For example:

void shoot(){
   motor.spin(directionType::fwd, 100, vex::velocityUnits::pct);
   task::sleep(1000);
   motor.stop(brakeType::coast);
       // intakes ball
   shooter.spin(directionType::fwd, 100, vex::velocityUnits::pct);
   task::sleep(500);
   shooter.stop(brakeType::coast);
      // shoots ball
}

int main(){
Controller1.pressed(shoot);
}

To clarify, what you refer to as “a void” is, in fact, known generally as a function.

The syntax for a function in C-like languages (VCS uses C++) is something like this:


return_type function_name(arguments) {
    // function body
}

The


void

keyword is a special return type that means a function doesn’t return any value.

With that in mind, see @jack202020 's answer

@jack202020 @hotel
Thak you so much! I will try it later this evening and I’ll see if it works.

Little update: it worked! I tweeked it a little bit according to what our team needed and it works. Thank you again @jack202020 and @hotel