Botton Pressed Error

I am trying to make it so when a button is pressed (not pressing) it runs a void function a parameter. This does work when I do not use a parameter, but when I be I get the following error:

./main.cpp:19:34: error: cannot initialize a parameter of type 'void (*)()' with an rvalue of type 'void'
    Controller1.ButtonX.released(centerActivate(SIG_1));
                                 ^~~~~~~~~~~~~~~~~~~~~

Here is the code:

bool currentlyCentered;
vex::vision::signature currentSignature;
bool objectCenter();
bool center(vex::vision::signature);
void centerActivate(vex::vision::signature);

int main() {
    while (true) {
    Controller1.ButtonX.released(centerActivate(SIG_1));
    }
    
    
    
}

void centerActivate(vex::vision::signature currentSignature) {
    currentlyCentered = false;
    xCentered = false;
    yCentered = false;
    while (currentlyCentered == false) {
        currentlyCentered = center(currentSignature);
    } 
}

I could be completely wrong, but I believe the error is because you define the void after you are calling it in the program.

What should I go about changing to fix it?

my experience with voids is very limited, but would it be possible to define the void before you are calling it through pressing the button?

I believe it is already defined beforehand in this line.

Ah, I see, I guess I’ll be of no use to you. You’ll need a true programmer for this job.

Ok. I hope one of those sees this thread.

Hm, guess that would be me.
You cannot pass a parameter to the ButtonX.released callback. The callback has to be of this form.

void callback() {
}

also…
don’t register a callback in a while loop. It should be registered once only.

Thanks, but now I am getting a different error:

./main.cpp:20:68: error: expected ‘(’ for function-style cast or type construction
Controller1.ButtonX.released( void (centerActivate(SIG_1))(void) ));

This is my code now:

int main() {
    while (true) {
    Controller1.ButtonX.released( void (centerActivate(SIG_1))(void) ));
    }
    
    
    
}

void centerActivate(vex::vision::signature currentSignature) {
    currentlyCentered = false;
    xCentered = false;
    yCentered = false;
    while (currentlyCentered == false) {
        currentlyCentered = center(currentSignature);
    } 
}

ok, you ignored both recommendations.

The callback needs to look like this, you cannot pass a parameter, you will need to figure out another way (i.e… global or something) to get currentSignature.

// will not work until currentSignature is defined
void centerActivate() {
    currentlyCentered = false;
    xCentered = false;
    yCentered = false;
    while (currentlyCentered == false) {
        currentlyCentered = center(currentSignature);
    } 
}

Then in main, only register it once.

int main() {
    Controller1.ButtonX.released(  centerActivate );

    while (true) {
      // more code
    }    
}

also, not sure exactly what you are trying to do, but signatures like SIG_1 are usually only passed to the vision sensor constructor. Use the takeSnapshot method to retrieve the latest data from the vision sensor.

see this for some example code.