Competition Code Error - Special for my class

I am a teacher at a high school in Ohio that is attempting to put on an in class robotics competition using VEX robots. I do not have the equipment to have a real field control system, however a colleague of mine mentioned I could design a template where pushing a bump switch will start autoanomus mode and then after the timer in the code runs out, the code would switch to a timed teleop mode. I have posted the code below, here are the current test results and error:

The first push does put it into autonomous mode but the assigned time does not cause the code to jump out of the while loop for the auto period, instead it continues to repeat the autonomous codes while loop. I was expecting the timer hitting 20 seconds to cause the while loop to become false and therefore move to the next line of code, which would cause it to move to the timed teleop while loop. Any help or guidance is deeply appreciated!

Beginning of Code:

task main()
{
int buttoncount; //create varible buttoncount to track number of times the auto bump switch is pressed.
buttoncount = 0; //set varible to zero
while(buttoncount==0) //Add loop for only buttoncount ==0
{
if(SensorValue(dgtl10)==1)
{
buttoncount = buttoncount + 1;//when the bump switch is pressed add 1 to “buttoncount”
}
}
//////////////////////////////////////////////////////////////////////////////////////////
//
// MODIFICATIONS ABOVE THIS LINE WILL CAUSE YOUR ROBOTS CODE TO BE RAN INCORRECTLY
//
// AUTOANOUMUS CODE
//
//////////////////////////////////////////////////////////////////////////////////////////

while(buttoncount == 1) //Autonamous starts when the bumpswitch is pressed once

{
clearTimer(T1);
while(time1[T1] < 20) //Autoanmous code will run for only 20 seconds. Modifications to this line will merit disqualification

{
while(1==1) //this is a students sample code I barrowedto test my template.
{
startMotor(port9, 127);
startMotor(port8, 127);
wait(6.5);
stopMotor(port9);
stopMotor(port8);
startMotor(port9, -127);
startMotor(port8, -127)
wait(2)
stopMotor(port9)
stopMotor(port8)
startMotor(port9, 127)
startMotor(port8, -127)
wait(1.5);
stopMotor(port9)
stopMotor(port8)
startMotor(port9, 127)
startMotor(port8, 127)
wait(5);
stopMotor(port9)
stopMotor(port8)
}
}

buttoncount = buttoncount + 1; //AFTER AUTOANMOUS ADD 1 TO THE VARIBLE. Modifications to this line will merit disqualification
}

/////////////////////////////////////////////////////////////////////////////////////////
//
// TELEOP CODE
//
/////////////////////////////////////////////////////////////////////////////////////////

while(buttoncount==2) //WHEN THE VARIBLE COUNT IS TWO RUN THE TELEOP CODE. Modifications to this line will merit disqualification
{
clearTimer(T2); //CLEAR THE SECOND TIMER. Modifications to this line will merit disqualification
while (time1[T2]<120) //RUN TEAM’S TELEOP CODE FOR 2 MINUTES. Modifications to this line will merit disqualification
{
while(1==1) //this is a students sample code I barrowedto test my template.
{
startMotor(port2,127);
startMotor(port3,127);
wait(15);
}}
}
buttoncount = buttoncount + 1; //AFTER TELEOP TIME EXPIRES ADD 1 TO THE VARIBLE. Modifications to this line will merit disqualification
}

This loop will never exit

while(1==1) //this is a students sample code I barrowedto test my template.

I’ll post some updated code for you later.

Here is a template that should do what you want. It uses tasks rather than trying to run the auto and driver code as part of the main program, this will allow both periods to be accurately timed without the concern that student code may have infinite loops. I left your times as 20 and 120 seconds for auto/driver periods but recently it has been 15 and 105 in competition.

#pragma config(Sensor, dgtl10, startSwitch,    sensorTouch)
#pragma config(Motor,  port1,            ,             tmotorVex393_HBridge, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

//////////////////////////////////////////////////////////////////////////////////////////
//  AUTONOMOUS CODE
//////////////////////////////////////////////////////////////////////////////////////////

task autonomous()
{
    // Student auton code
    motor port1 ] = 100;
    wait1Msec(1000);
    motor port1 ] = 0;
}

//////////////////////////////////////////////////////////////////////////////////////////
// TELEOP CODE
//////////////////////////////////////////////////////////////////////////////////////////

task usercontrol()
{
    // Student driver code  
    while(1) {
      motor port1 ] = vexRT Ch2 ];
      
      wait1Msec(10);
    }
}

//////////////////////////////////////////////////////////////////////////////////////////
// MODIFICATIONS BELOW THIS LINE WILL CAUSE YOUR ROBOTS CODE TO BE RUN INCORRECTLY
//////////////////////////////////////////////////////////////////////////////////////////

void
allMotorStop()
{
  motor port1  ] = 0;  
  motor port2  ] = 0;  
  motor port3  ] = 0;  
  motor port4  ] = 0;  
  motor port5  ] = 0;  
  motor port6  ] = 0;  
  motor port7  ] = 0;  
  motor port8  ] = 0;  
  motor port9  ] = 0;  
  motor port10 ] = 0;  
}

task main()
{
    // Wait for initial button push
    while( SensorValue startSwitch ] == 0 ) {
      wait1Msec(10);
    }

    // Start auton
    clearTimer(T1);
    startTask( autonomous );
  
    // Wait for 20 seconds (20000mS)
    while( time1[T1] < 20 * 1000 )
      wait1Msec(10);
  
    // stop the auton task
    stopTask( autonomous );
    allMotorStop();
    
    // Perhaps a delay before driver starts
    //wait1Msec(5 * 1000);
    
    // Start the driver control period
    clearTimer(T1);
    startTask( usercontrol );
    
    // Wait for 120 seconds (120000mS)
    while( time1[T1] < 120 * 1000 )
      wait1Msec(10);
    
    // Stop driver control
    stopTask( usercontrol );
    allMotorStop();
  
    // Done
    while(1)
      wait1Msec(10);
}