I need help with code

`
#include “vex.h”
#include <vex_controller.h>
using namespace vex;

int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
motor Mot1 = motor(PORT1, ratio18_1, false);//initializes motors counter clockwise
motor Mot2 = motor(PORT2, ratio18_1, true);//initilizes port 2 , clockwise
motor_group left( Mot1, Mot2 );//initializes motor group of mot1 and mot2
while (true){
if(controller.ButtonA.pressing())//checks if a is pressed
{
left.spin(reverse,200,rpm);//spins reversed at -50 rpm
}
else if(controller.ButtonA.pressing())
{
left.spin(reverse,200,rpm);
}
else
{
left.stop();
}
}
}
`

in if(controller.ButtonA.pressing() there is an issue with the dot operator idk what to do.

What editor are you using? Does anything come up when you mouse over it (the redline, or whatever is indicating the issue)?

Use ` before and after code to trigger syntax highlighting on the forum. Then indent properly so we can read the code:

#include “vex.h”
#include <vex_controller.h>
using namespace vex;

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();
  motor Mot1 = motor(PORT1, ratio18_1, false);//initializes motors counter clockwise
  motor Mot2 = motor(PORT2, ratio18_1, true);//initilizes port 2 , clockwise
  motor_group left( Mot1, Mot2 );//initializes motor group of mot1 and mot2
  while (true) {
    if(controller.ButtonA.pressing()) //checks if a is pressed
    {
      left.spin(reverse,200,rpm);//spins reversed at -50 rpm
    } else if(controller.ButtonA.pressing()) {
      left.spin(reverse,200,rpm);
    } else {
      left.stop();
    }
  }
}

I think you might need to define a controller first.

vex::controller Controller1 = vex::controller();

From here. I suspect this is done in some kind of robot configuration within the IDE like it was in RobotC. You can check the robot-config.h header, see if a controller is defined and make sure the name matches.

4 Likes

when I hover over the red line it says “cannot use dot operator on a type”. Also how do I add stuff to the robot-config.h.

If you’re using VEXcode V5 Text…

Maybe you need to capitalise controller? This builds just fine for me, when I plugged it in with my code (FLDrive is my motor, in your case it would be “left”).

if(Controller.ButtonA.pressing())//checks if a is pressed
  {
    FLDrive.spin(reverse,200,rpm);//spins reversed at -50 rpm
  }
  else if(Controller.ButtonA.pressing())
  {
    FLDrive.spin(reverse,200,rpm);
  }
  else
  {
    FLDrive.stop();
  }

also, did you initialise your motors at the beginning of the code? Like, putting this right after the //_________Devices _________ thing?

//vex::brain Brain;

vex::competition Competition;

vex::controller Controller = vex::controller();

vex::controller Controller2 = vex::controller(vex::controllerType::partner);

vex::motor FRDrive = vex::motor(vex::PORT1);

vex::motor FLDrive = vex::motor(vex::PORT2);

vex::motor BLDrive = vex::motor(vex::PORT3);

vex::motor BRDrive = vex::motor(vex::PORT4);
3 Likes

I cant access the devices

Ok so before I can really help you, I need to know what platform you’re using. Are you using VEXcode v5 text? Or blocks? Or what else?

2 Likes

I am using VEXcode v5 text

Great!
So when you load it up, the blank template should look like this.

/*----------------------------------------------------------------------------*/
/*                                                                            */
/*    Module:       main.cpp                                                  */
/*    Author:       C:\Users\sofia                                            */
/*    Created:      Sun Dai 57 2080                                           */
/*    Description:  V5 project                                                */
/*                                                                            */
/*----------------------------------------------------------------------------*/

// ---- START VEXCODE CONFIGURED DEVICES ----
// ---- END VEXCODE CONFIGURED DEVICES ----

#include "vex.h"

using namespace vex;

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

Right after using namespace vex; you should put in the

//vex::brain Brain;

vex::competition Competition;

vex::controller Controller = vex::controller();

vex::motor LeftMotor = vex::motor(vex::PORT1);

vex::motor RightMotor = vex::motor(vex::PORT2);

Then, after that, capitalise Controller in your code, change the motor names, and you should be fine. The end product should look like this:

/*----------------------------------------------------------------------------*/
/*                                                                            */
/*    Module:       main.cpp                                                  */
/*    Author:       C:\Users\sofia                                            */
/*    Created:      Sun Dai 57 2080                                           */
/*    Description:  V5 project                                                */
/*                                                                            */
/*----------------------------------------------------------------------------*/

// ---- START VEXCODE CONFIGURED DEVICES ----
// ---- END VEXCODE CONFIGURED DEVICES ----

#include "vex.h"

using namespace vex;

//vex::brain Brain;

vex::competition Competition;

vex::controller Controller = vex::controller();

vex::motor LeftMotor = vex::motor(vex::PORT1);

vex::motor RightMotor = vex::motor(vex::PORT2);


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

  while (1) { // you can sub the 1 for true, it will result in the same thing lolz

    if(Controller.ButtonA.pressing())//checks if a is pressed
    {
      LeftMotor.spin(reverse,200,rpm);//spins reversed at -50 rpm
    }
    else if(Controller.ButtonA.pressing())
    {
      LeftMotor.spin(reverse,200,rpm);
    }
    else
    {
      LeftMotor.stop();
    }

  }
  
}

Don’t forget to press “Build” in the right hand corner (it looks like 3 cubes stacked) to make sure it works correctly!
Good luck, and I hope this helped! :smiley:

6 Likes

Thank you very much!

1 Like