RobotC Drive function problem

Could someone look at this and maybe see why it is not working? I made a function for driving so it would be easier to program Autons, but i cant get it to even work for driving. :frowning: is there something I missed or just did wrong?


#pragma config(Motor,  port2,           FrontLeftGB,   tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor,  port3,           BackLeftGB,    tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port4,           FrontRightGB,  tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port5,           BackRightGB,   tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor,  port6,           FrontLeft,     tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port7,           FrontRight,    tmotorVex393_MC29, openLoop, reversed)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//


void drive(int left, int right, int time)//Time is for the Auton UNUSED in drive method
{
	//Left Side Drive
	motor[FrontLeft] = left;
	motor[FrontLeftGB] = left;
	motor[BackLeftGB] = left;
	//Right Side Drive
	motor[FrontRight] = right;
	motor[FrontRightGB] = right;
	motor[BackRightGB] = right;
	wait1Msec(time);
}

task main()
{
	bLCDBacklight = true;									// Turn on LCD Backlight
	string mainBattery;
	while (1 == 1)
	{
		clearLCDLine(0);
		clearLCDLine(1);
		//Display the Primary Robot battery voltage
		displayLCDString(0, 0, "Primary: ");
		sprintf(mainBattery, "%1.2f%c", nImmediateBatteryLevel/1000.0,'V'); //Build the value to be displayed
		displayNextLCDString(mainBattery);
		displayLCDString(1, 0, "Good Luck!");

		//Short delay for the LCD refresh rate
		wait1Msec(100);
	}

	while (1 == 1)
	{
		drive(vexRT[Ch3], vexRT[Ch2], 0);
	}
}

As others have said in this thread.
https://vexforum.com/t/unofficial-reply-to-robotc-drive-function-problem/40795/1

You have two while loops, the first does not exit and therefore the second one will never be reached. To display battery voltage and drive the robot, place both functions inside the same while loop. Don’t worry about the LCD refresh delay, that’s completely unnecessary and handled by RobotC, however, it is good practice to place a few mS delay at the end of while loops to help the RobotC scheduler.

#pragma config(Motor,  port2,           FrontLeftGB,   tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor,  port3,           BackLeftGB,    tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port4,           FrontRightGB,  tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port5,           BackRightGB,   tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor,  port6,           FrontLeft,     tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port7,           FrontRight,    tmotorVex393_MC29, openLoop, reversed)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//


void drive(int left, int right, int time)//Time is for the Auton UNUSED in drive method
{
    //Left Side Drive
    motor[FrontLeft] = left;
    motor[FrontLeftGB] = left;
    motor[BackLeftGB] = left;
    //Right Side Drive
    motor[FrontRight] = right;
    motor[FrontRightGB] = right;
    motor[BackRightGB] = right;
    wait1Msec(time);
}

task main()
{
    bLCDBacklight = true; // Turn on LCD Backlight
    string mainBattery;
    
    clearLCDLine(0);
    clearLCDLine(1);
    displayLCDString(1, 0, "Good Luck!");

    while (1 == 1)
    {
        //Display the Primary Robot battery voltage
        displayLCDString(0, 0, "Primary: ");
        sprintf(mainBattery, "%1.2f%c", nImmediateBatteryLevel/1000.0,'V'); //Build the value to be displayed
        displayNextLCDString(mainBattery);

        // drive
        drive(vexRT[Ch3], vexRT[Ch2], 0);

        // Don't hog cpu
        wait1Msec(20);
    }
}