I already know how to use the controller.buttonA.pressed(function); command, but how do you use it like this: controller.buttonA.pressed(function(parameter1, parameter2));
Here is a snippet of my code that uses those functions and the errors I got: Controller1.ButtonA.pressed(driveDistance(10, 100));
[clang] Cannot initialize a parameter of type ‘void (*)()’ with an rvalue of type ‘void’
Then that is something VEX needs to add. I don’t see any reason why it shouldn’t be possible. I am pretty amazed that I actually stumbled upon something that is not possible in programming. I do not see that often. I know someone that used to program in C++ for his job and every time I have talked with him about a problem that I can’t solve he always says that there is a way. For this apparently not.
You could assign the values you want to pass to the function to globals, set them prior to calling the function, then have the function read the globals when called.
Its not that it is impossible, just impossible as you wrote it.
OK. What I was trying to do was make it move 10 inches every time I pressed the button. Could this also work? if (Controller1.ButtonA.pressing()) { driveDistance(10, 100); }
where you were passing several parameters into the pressed event registration call, that’s not possible. If you want to write your own event handling code then it would be, but we chose not to do that.
There are other ways for you to accomplish this without asking for lots of bells and whistles that satisfy your need - but as written the .pressed is quite powerful.
I reading this and I sort of understand it. (Yes I understand this is an old thread) in the pressed(); does it read and execute what’s in the parentheses?