I need help adding a time parameter to my autonomous function

59 PM
my void is
void goForward(){
LF.spin(vex::directionType::fwd,100,vex::velocityUnits::pct);
RF.spin(vex::directionType::fwd,100,vex::velocityUnits::pct);
LB.spin(vex::directionType::fwd,100,vex::velocityUnits::pct);
RB.spin(vex::directionType::fwd,100,vex::velocityUnits::pct);
wait(10, msec);
LF.stop();
RF.stop();
LB.stop();
RB.stop();
}
void goBackward(){
LF.spin(vex::directionType::rev,100,vex::velocityUnits::pct);
RF.spin(vex::directionType::rev,100,vex::velocityUnits::pct);
LB.spin(vex::directionType::rev,100,vex::velocityUnits::pct);
RB.spin(vex::directionType::rev,100,vex::velocityUnits::pct);
wait(10, msec);
// Stop all the motors so it will do the next step.
LF.stop();
RF.stop();
LB.stop();
RB.stop();
}
void goRight(){
LF.spin(vex::directionType::fwd,100,vex::velocityUnits::pct);
RF.spin(vex::directionType::rev,100,vex::velocityUnits::pct);
LB.spin(vex::directionType::fwd,100,vex::velocityUnits::pct);
RB.spin(vex::directionType::rev,100,vex::velocityUnits::pct);
wait(10, msec);
// Stop all the motors so it will do the next step.
LF.stop();
RF.stop();
LB.stop();
RB.stop();
}
void goLeft(){
LF.spin(vex::directionType::rev,100,vex::velocityUnits::pct);
RF.spin(vex::directionType::fwd,100,vex::velocityUnits::pct);
LB.spin(vex::directionType::rev,100,vex::velocityUnits::pct);
RB.spin(vex::directionType::fwd,100,vex::velocityUnits::pct);
wait(10, msec);
// Stop all the motors so it will do the next step.
LF.stop();
RF.stop();
LB.stop();
RB.stop();
}

In your function, it has no parameters, so when you call the function you don’t need any parameters.

When you want to use your function you just do

goForward();

but wouldn’t that make it infinitely continue that command and not change to the next one?

No it would run for only 10ms and continue to the next one which was probably not what you were going for. You need to add parameters to when you created your function

void goForward(int x){
LF.spin(vex::directionType::fwd,100,vex::velocityUnits::pct);
RF.spin(vex::directionType::fwd,100,vex::velocityUnits::pct);
LB.spin(vex::directionType::fwd,100,vex::velocityUnits::pct);
RB.spin(vex::directionType::fwd,100,vex::velocityUnits::pct);
wait(x, msec);
LF.stop();
RF.stop();
LB.stop();
RB.stop();
}

So when you want it to run for 400 Ms you do:
goForward(400);

1 Like

but then it gives me the error in the pic

If you want to run your function for a certain amount of time, you need to add parameters to your functions. like such void driveforward(int time)
Time is a variable that you can use within your function but from the looks of it, you already have time values in your wait commands so, like thorstenl312 said you can just call your function with no parameters. Also, this is VexCode, not VCS

Yes, remove the ,msec part from your line of code that’s giving the error

05 PM

Look at the code I posted earlier and see if it matches

void goForward(int x){
LF.spin(vex::directionType::fwd,100,vex::velocityUnits::pct);
RF.spin(vex::directionType::fwd,100,vex::velocityUnits::pct);
LB.spin(vex::directionType::fwd,100,vex::velocityUnits::pct);
RB.spin(vex::directionType::fwd,100,vex::velocityUnits::pct);
wait(x, msec);
LF.stop();
RF.stop();
LB.stop();
RB.stop();
}
1 Like

does the x in the int have to be time or?

The ‘int x’ part is a parameter which is used to tell how long the motors run for. You can see I declare int x in the first line of the function and then use x in wait(x,msec);

So whatever number you use for x, it will go into the wait(x,msec);

1 Like

it shows the same error

Can you post the code for your goForward function?

void.h file, line 2

void goForward(int x){

Make sure to save the void.h file too. You can see if it’s saved or not if there’s a white dot next to the file name

2 Likes

yo thanks for the help

1 Like