I have an issue with my code

the “[ ]” are being shown as an error.
it was written using Vex V5 Pro

here’s the code

#include "vex.h"
brain Brain; 
vex::vision::signature SIG_1 = vex::vision::signature (1, 0, 0, 0, 0, 0, 0, 2.5, 0);
vex::vision::signature SIG_2 = vex::vision::signature (2, 0, 0, 0, 0, 0, 0, 2.5, 0);
vex::vision Vision12_objectIndex = vex::vision (vex::PORT12, 50, SIG_1, SIG_2);
motor elbow = motor(PORT3); 
motor claw = motor(PORT8, true);

using namespace vex;

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();


}
int whenStarted1() {
 while (true) { // No Vision Sensor signature selected
  if (Vision12.objects[Vision12_objectIndex].width > 125.0) {
    claw.spin(forward);
    elbow.spin(reverse);
  }
  else {
    if (Vision12.objectCount > 0) {
      if (Vision12.objects[Vision12_objectIndex].centerX > 100.0) {
          Drivetrain.turn(right);
      }
      if (Vision12.objects[Vision12_objectIndex].centerX < 60.0) {
          Drivetrain.turn(left);
      }
      if (Vision12.objects[Vision12_objectIndex].centerX > 60.0 && Vision12.objects[Vision12_objectIndex].centerX < 100.0) {
        if (Vision12.objects[Vision12_objectIndex].width < 125.0) {
          Drivetrain.drive(forward);
        }
        else {
          Drivetrain.stop();
        }
      }
    }
    else {
      Drivetrain.setTurnVelocity(25.0, percent);
      Drivetrain.turn(right);
    }
  }
wait(20, msec);
}
}

edit by mods: format code

First off, welcome to the forums!
Secondly, you should format code with ``` at the beginning and end.
And thirdly, could you share a screenshot of the error? We’ll be able to help more if we know the error we’re helping to fix.

2 Likes

You are trying to pass an instance of the vision class as an index to the objects array. It should be an integer. and Vision12 does not seem to be defined anywhere (which should be the vision instance). Was this code cut and pasted from a blocks program ?

2 Likes

it was, I am new to coding so I decided to use bocks firs then convert it to text and the Vision12 variable is define but it is not in the image I sent

The C++ that a blocks program generates is not a great starting place for writing good C++ code. There are compromises that have to be made when the code is generated from blocks, and other intermediate variables that get used.

To get going, just replace the Vision12_objectIndex variable (you should remove that from the program completely, including the definition). with 0 (or 1 for the second object etc.)

2 Likes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.