Pneumatic Coding

Was trying this pneumatic code:
/// #include “vex.h”

using namespace vex;

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

// “when started” hat block
int whenStarted1() { $$$
DigitalOutA.set(false);
return 0;
}

// “when Controller1 ButtonA pressed” hat block
void onevent_Controller1ButtonA_pressed_0() {$$$
DigitalOutA.set(true);
}

// “when Controller1 ButtonB pressed” hat block
void onevent_Controller1ButtonB_pressed_0() {$$$
DigitalOutA.set(false);
}

int main() {$$$
// register event handlers
Controller1.ButtonA.pressed(onevent_Controller1ButtonA_pressed_0);
Controller1.ButtonB.pressed(onevent_Controller1ButtonB_pressed_0);

}

}
///

but an error message appears on lines 27,33,38,43 saying function definition is not allowed here
I have marked these lines with triple dollar sign: $$$

You defined all of your functions inside of a function, which isn’t allowed. You should remove the outer main function, because it’s not necessary and just breaks the code. (basically delete the first line that says int main() { and the last curly bracket)

1 Like

unfortunately that doesnt work

Don’t remove int main(). Simply move all of your function definitions to be outside of the main function. Example:

 #include “vex.h”

using namespace vex;

int myfunction(int a) {
return a*7 + 6;
}

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

Additionally, you somehow created an int main function inside of the already existing int main function. Remove the int main() { and matching curly bracket further down in your code

2 Likes