This code seems to just -- not execute, can't diagnose why

Hello, this is a weird thing happening. A couple of my students put this code together for a clawbot using a VEX Cortex. It compiles (or at least there is no error message). The firmware download was up to date. All the motors seem to be connected in the right ports.

But when we ran the code, nothing happens. And more interesting, the indicators in RobotC that usually highlight the instruction executing seem to say nothing is happening.

I thought initially it might be the ports. But what’s so weird is that even then, you see the highlight bar going through the instructions, you see the debugger window say if there is power going to the motors, all that stuff. In this case it’s as though the code just doesn’t execute to begin with. I thought it might be the USB cable but then it wouldn’t have successfully downloaded the firmware or the code.

Anyhow, I am posting this here. I thought there must be some silly mistake we are making. But if it were a syntax error it wouldn’t compile. Ideas welcome, and thank you in advance.

.
#pragma config(Motor, port1, leftmotor, tmotorNone, openLoop)
#pragma config(Motor, port6, clawmotor, tmotorNone, openLoop)
#pragma config(Motor, port7, armmotor, tmotorNone, openLoop)
#pragma config(Motor, port10, rightmotor, tmotorNone, openLoop)
//!!Code automatically generated by ‘ROBOTC’ configuration wizard !!//

task main()
{
{int direction;
direction = 0;
repeat(forever)

direction = random(1);
if (direction == 0)
{
startMotor(leftmotor,-10);
startMotor(rightmotor,10);
wait(2);
stopMotor(leftmotor);
stopMotor(rightmotor);
startTask (leftmotor,-10);
startTask(rightmotor,10);
wait(1);}
startMotor(leftmotor,-10);
startMotor(leftmotor,10);
{
stopMotor(leftmotor);
stopMotor(rightmotor);
startTask(leftmotor,10);
startTask (rightmotor,-10);
wait(1);}

}}

extra brackets everywhere

and your repeat forever doesnt have a bracket.

4 Likes

All the program will do is this

repeat(forever)
   direction = random(1);

as @Deicer suggested, sort out the formatting and get all the braces in the correct places.

7 Likes

AHA!

Thanks to you both @jpearman and @Deicer – I suspected it was something silly like that. I hadn’t noticed the placement of the repeat forever outside the brackets. Silly, that.

Thanks you both so much. Sometimes the little things get you.

2 Likes