How do you make a touch button a toggle switch in RobotC for Sumobot

I can’t figure out how to make a touch button a toggle switch in RobotC for vex EDR…

Here is what I have so far:

task main()
{
while (1==1)
{while(SensorValue(StartStopButton)==1) /Start/
{if(SensorValue(SonarF) > 10)/Determine which Sonar/
{startMotor(MotorR, 50);
startMotor(MotorL, 50);}
else
{if(SensorValue(SonarR)>10) /Determine which Sonar/
{startMotor(MotorF, 50);
startMotor(MotorB, 50);}
else
{if(SensorValue(SonarB)>10) /Determine which Sonar/
{startMotor(MotorR, -50);
startMotor(MotorL, -50);}
else
{if(SensorValue(SonarL)>10) /Determine which Sonar/
{startMotor(MotorF, -50);
startMotor(MotorB, -50);}
else
{stopMotor(MotorF);
stopMotor(MotorR);
stopMotor(MotorB);
stopMotor(MotorL);}
}
untilTouch(StartStopButton); /EMERGENCY STOP/
stopMotor(MotorR);
stopMotor(MotorL);
stopMotor(MotorF);
stopMotor(MotorB);
}
}
}
}
}

Any help please?

Thanks,
Hettyc Tracyn

Update:

task main()
{
run=0;
buttonpress=0;
while (1==1)
{
if(SensorValue(StartStopButton))
{buttonpress=1;}
if(buttonpress && run==0)
{
run=1;
buttonpress=0;
}
if(buttonpress && run==1)
{
run=0;
buttonpress=0;
}
if(run)
{
if(SensorValue(SonarF) > 10)/Determine which Sonar/
{startMotor(MotorR, 50);
startMotor(MotorL, 50);}
else
{if(SensorValue(SonarR)>10) /Determine which Sonar/
{startMotor(MotorF, 50);
startMotor(MotorB, 50);}
else
{if(SensorValue(SonarB)>10) /Determine which Sonar/
{startMotor(MotorR, -50);
startMotor(MotorL, -50);}
else
{if(SensorValue(SonarL)>10) /Determine which Sonar/
{startMotor(MotorF, -50);
startMotor(MotorB, -50);}
else
{stopMotor(MotorF);
stopMotor(MotorR);
stopMotor(MotorB);
stopMotor(MotorL);}
}
untilTouch(StartStopButton); /EMERGENCY STOP/
stopMotor(MotorR);
stopMotor(MotorL);
stopMotor(MotorF);
stopMotor(MotorB);
}
}
}
}
}

Another update:

int run;
int buttonpress;

task main()
{
run=0;
buttonpress=0;
while (1==1)
{
if(SensorValue(StartStopButton))
{buttonpress=1;}
if(buttonpress && run==0)
{
run=1;
buttonpress=0;
}
if(buttonpress && run==1)
{
run=0;
buttonpress=0;
}
if(run)
{
if(SensorValue(SonarF) > 10)/Determine which Sonar/
{startMotor(MotorR, 50);
startMotor(MotorL, 50);}
else
{if(SensorValue(SonarR)>10) /Determine which Sonar/
{startMotor(MotorF, 50);
startMotor(MotorB, 50);}
else
{if(SensorValue(SonarB)>10) /Determine which Sonar/
{startMotor(MotorR, -50);
startMotor(MotorL, -50);}
else
{if(SensorValue(SonarL)>10) /Determine which Sonar/
{startMotor(MotorF, -50);
startMotor(MotorB, -50);}
else
{stopMotor(MotorF);
stopMotor(MotorR);
stopMotor(MotorB);
stopMotor(MotorL);}
}
untilTouch(StartStopButton); /EMERGENCY STOP/
stopMotor(MotorR);
stopMotor(MotorL);
stopMotor(MotorF);
stopMotor(MotorB);
}
}
}
}
}

Final update I think:

int run;
int buttonpress;

task main()
{
run=0;
buttonpress=0;
while (1==1)
{
if(SensorValue(StartStopButton))
{buttonpress=1;}
if(buttonpress && run==0)
{
run=1;
buttonpress=0;
}
if(buttonpress && run==1)
{
run=0;
buttonpress=0;
}
if(run)
{
if(SensorValue(SonarF) > 10)/Determine which Sonar/
{startMotor(MotorR, 50);
startMotor(MotorL, 50);}
else
{if(SensorValue(SonarR)>10) /Determine which Sonar/
{startMotor(MotorF, 50);
startMotor(MotorB, 50);}
else
{if(SensorValue(SonarB)>10) /Determine which Sonar/
{startMotor(MotorR, -50);
startMotor(MotorL, -50);}
else
{if(SensorValue(SonarL)>10) /Determine which Sonar/
{startMotor(MotorF, -50);
startMotor(MotorB, -50);}
else
{stopMotor(MotorF);
stopMotor(MotorR);
stopMotor(MotorB);
stopMotor(MotorL);}
}
/Linefollowers/

if(SensorValue(LineFollowerR) < 10) /*determine which Line follower*/
{startMotor(MotorF, 50);
	startMotor(MotorB, -50);} /*motor speed/direction*/
	else
		{if(SensorValue(LineFollowerL) < 10) /*determine which Line follower*/
				{startMotor(MotorF, -50);
				startMotor(MotorB, 50);} /*motor speed/direction*/
			else
				{if(SensorValue(LineFollowerF) < 10) /*determine which Line follower*/
						{startMotor(MotorR, -50);
						startMotor(MotorL, -50);} /*motor speed/direction*/
					else
	
						if(SensorValue(LineFollowerB) < 10) /*determine which Line follower*/
								{startMotor(MotorR, -50);
								startMotor(MotorL, -50);} /*motor speed/direction*/
							
}	
}

untilTouch(StartStopButton); /EMERGENCY STOP/
stopMotor(MotorR);
stopMotor(MotorL);
stopMotor(MotorF);
stopMotor(MotorB);
}
}
}
}
}

Thanks and your welcome:
Hettyc Tracyn