Boolean callback help

I have some code and I have no idea why there are errors please help.
(this is c++ btw)
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();

Inertial21.calibrate();

bool inertialon,inertialoff;

void turnon()
{
inertialoff;
}
while(true){
Controller1.buttonup.pressed(turnon);
}
}

bool inertialon,inertialoff;

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

Inertial21.calibrate();

while(true){
 if(Controller1.buttonup.pressed()){
   turnon();
  }
 }
}

void turnon(){
inertialoff = true;
}

Haven’t really used much vexcode but for starters, you have a function in a function, it needs to be out of that scope. Same goes with your bools, they need to be in a global scope, not local to the int main function. (hopefully I’m not talking bs, if I said something stupid correct me).

6 Likes

The correct function call is if( Controller1.buttonup.pressing() ) { ... } which returns true when button is pressed in.

You don’t want to use pressed(callBackFunction) which creates a new thread every time it is called and will fail after 100 times.

See here:

https://api.vexcode.cloud/v5/html/classvex_1_1controller_1_1button.html#abf18ef5acb8d3885d206d5f5bfa02cf3

2 Likes