Why does my code stop working on vex coding studio?

Im trying to code autonomous but whenever i add the last 5 lines the code doesn’t run how it previously did with the added ending. Im not sure what to do. Here is the code.

#include “robot-config.h”
int main() {
//Shoot Catapult
LeftCatapult.spin(directionType::rev,100,velocityUnits::pct);
RightCatapult.spin(directionType::rev,100,velocityUnits::pct);
task::sleep(1000);
LeftCatapult.stop(brakeType::brake);
RightCatapult.stop(brakeType::brake);
//Turn Bot
LeftMotor.spin(directionType::rev,75,velocityUnits::rpm);
RightMotor.spin(directionType::fwd,75,velocityUnits::rpm);
BackLeftMotor.spin(directionType::rev,75,velocityUnits::rpm);
BackRightMotor.spin(directionType::fwd,75,velocityUnits::rpm);
task::sleep(800);
LeftMotor.stop(brakeType::brake);
RightMotor.stop(brakeType::brake);
BackLeftMotor.stop(brakeType::brake);
BackRightMotor.stop(brakeType::brake);
//Move Bot Forward
LeftMotor.startRotateFor(50,rotationUnits::deg,100,velocityUnits::pct);
RightMotor.startRotateFor(50,rotationUnits::deg,100,velocityUnits::pct);
BackLeftMotor.startRotateFor(50,rotationUnits::deg,100,velocityUnits::pct);
BackRightMotor.startRotateFor(50,rotationUnits::deg,100,velocityUnits::pct);
//Move Bot Backward
LeftMotor.startRotateFor(-1200,rotationUnits::deg,-90,velocityUnits::pct);
RightMotor.startRotateFor(-1200,rotationUnits::deg,-100,velocityUnits::pct);
BackLeftMotor.startRotateFor(-1200,rotationUnits::deg,-90,velocityUnits::pct);
BackRightMotor.startRotateFor(-1200,rotationUnits::deg,-100,velocityUnits::pct);
//Move Bot Forward
LeftMotor.startRotateFor(50,rotationUnits::deg,100,velocityUnits::pct);
RightMotor.startRotateFor(50,rotationUnits::deg,100,velocityUnits::pct);
BackLeftMotor.startRotateFor(50,rotationUnits::deg,100,velocityUnits::pct);
BackRightMotor.startRotateFor(50,rotationUnits::deg,100,velocityUnits::pct);
}

You could try making the end of the last line in each block (separated by comments) blocking, so it’ll finish the stuff before it before moving on to the next block. I believe the syntax is just adding “, false” (or true) after the pct at the end.

That, and put a 50 or 100 ms wait statement after each block, so the brain can catch up. Hope that helps.

The Motor.startRotateFor() is non-blocking, so I think it’s waiting for a Motor.rotateFor() to trigger the other motors movement. You can try to switch the last line in each of the movements to use rotateFor() but won’t fix the issue (Thanks @jpearman for the clarification)

This describes Blocking / Non-Blocking functions:

https://help.vex.com/article/120-how-to-use-blocking-vs-non-blocking-code

Updated code using rotateFor()

#include “robot-config.h”
int main() {
	//Shoot Catapult
	LeftCatapult.spin(directionType::rev,100,velocityUnits::pct);
	RightCatapult.spin(directionType::rev,100,velocityUnits::pct);
	task::sleep(1000);
	LeftCatapult.stop(brakeType::brake);
	RightCatapult.stop(brakeType::brake);
	
	//Turn Bot
	LeftMotor.spin(directionType::rev,75,velocityUnits::rpm);
	RightMotor.spin(directionType::fwd,75,velocityUnits::rpm);
	BackLeftMotor.spin(directionType::rev,75,velocityUnits::rpm);
	BackRightMotor.spin(directionType::fwd,75,velocityUnits::rpm);
	task::sleep(800);
	LeftMotor.stop(brakeType::brake);
	RightMotor.stop(brakeType::brake);
	BackLeftMotor.stop(brakeType::brake);
	BackRightMotor.stop(brakeType::brake);
	
	//Move Bot Forward
	LeftMotor.startRotateFor(50,rotationUnits::deg,100,velocityUnits::pct); // Non-blocking
	RightMotor.startRotateFor(50,rotationUnits::deg,100,velocityUnits::pct); // Non-blocking
	BackLeftMotor.startRotateFor(50,rotationUnits::deg,100,velocityUnits::pct); // Non-blocking
	BackRightMotor.rotateFor(50,rotationUnits::deg,100,velocityUnits::pct); // Blocking
	
	//Move Bot Backward
	LeftMotor.startRotateFor(-1200,rotationUnits::deg,-90,velocityUnits::pct); // Non-blocking
	RightMotor.startRotateFor(-1200,rotationUnits::deg,-100,velocityUnits::pct); // Non-blocking
	BackLeftMotor.startRotateFor(-1200,rotationUnits::deg,-90,velocityUnits::pct); // Non-blocking
	BackRightMotor.rotateFor(-1200,rotationUnits::deg,-100,velocityUnits::pct); // Blocking
	
	//Move Bot Forward
	LeftMotor.startRotateFor(50,rotationUnits::deg,100,velocityUnits::pct); // Non-blocking
	RightMotor.startRotateFor(50,rotationUnits::deg,100,velocityUnits::pct); // Non-blocking
	BackLeftMotor.startRotateFor(50,rotationUnits::deg,100,velocityUnits::pct); // Non-blocking
	BackRightMotor.rotateFor(50,rotationUnits::deg,100,velocityUnits::pct); // Blocking
}

Posting code with Syntax Highlighting

Also, you probably want to use fenced code blocks so that your code is easier to read, here’s how you can do it:

Not really, the separate instances of the motors don’t know what the others are doing, however, if you don’t wait for the Motor.startRotateFor command to complete the request and simply send it another Motor.startRotateFor or Motor.spin command, then whatever has been sent to the motor last will be what is does.