How to use button.released?

I’m confused as to how to use the button.released command, like is it a check like how button.pressing works? How’d i implement it into my code. I need it because a button check is checking right after it was pressed and i want the code to wait until the button is no longer pressed.

released() function takes another function as a parameter. When ever the button gets released it calls that function once. It would be used like this…

void buttonARel()
{
    //button A was released: do stuff
}

vex::controller Controller1(vex::primary);

int main()
{
    Controller1.ButtonA.released(buttonARel);

    //do stuff
}

Alternative if you don’t want to use this you can do something like this…

bool buttonAState = false;

int main()
{
    while(true)
    {
        if(!Controller1.ButtonA.pressing() && buttonAState)
        {
            buttonAState = false;
            //button A was released: do stuff
        }
        if(Controller1.ButtonA.pressing()) buttonAState = true

       //do stuff
    }
}
Advanced way of doing it...
/*
    0 = unpressed
    1 = first press cycle
    2 = pressed
    3 = first unpress cycle
*/
int btnA = 2;

int main()
{
    while(true)
    {
        if(btnA != (Controller1.ButtonA.pressing() * 2)) btnA = (btnA + 1) % 4;

        if(btnA == 3)
        {
            buttonAState = false;
            //button A was released: do stuff
        }

       //do stuff
    }
}

Both of these achieve the same exact thing

2 Likes

ok thanks! this should come in handy