How to write a code moving motors if the axis value is not 0

Hi there! I need some help.
When coding our bot, our team want to write a code so that the robot will move up and down depending on the value on axis 3 of our controller, and turn left or right depending on the value of the axis 1 of our controller, all having a delay between movements.

the code we have now is this:

if (Controller1.Axis3.position(percentUnits::pct)) != 0{
        LeftMotor.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct);
        RightMotor.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct);
        if (Controller1.Axis1.position(percentUnits::pct)) != 0{
        LeftMotor.spin(vex::directionType::fwd, Controller1.Axis1.value(), vex::velocityUnits::pct);
        RightMotor.spin(vex::directionType::fwd, Controller1.Axis1.value(), vex::velocityUnits::pct);

However, when we compile, an "expected expression error shows up, with the first line of the code above.

What modifications do we need to make to our code so that it does as mentioned above?

This line is malformed. In C, any logical test after an if needs to be in (parentheses). The !=0 is hanging out.

1 Like

You if statement needs the comparison within the parentheses.

  if (Controller1.Axis3.position(percentUnits::pct)) != 0 { } 

move the )

  if (Controller1.Axis3.position(percentUnits::pct) != 0 )  {  }
1 Like

thanks that really helped!