RobotC programming infinite loop with autonomous option

I am looking for help programming an autonomous function into our current code that runs in an infinite loop.

Our robot runs a infinite loop code to drive through a course and complete tasks. On task we would like to complete is an autonomous challenge in the contest. We want to drive our robot as it currently is and then assign the autonomous code to a button on the controller and have it complete the code.

Here is some code that I wrote based on some videos I found on YouTube but we can’t figure out how to make the original code ignore this code until we press the assigned button. Thanks for any help you can provide.

Forward 2 seconds

wait 1 second

clamp down

wait 1second

raise 1 second

wait 1 second

reverse 2 seconds

task autonomous ()

//Forward

motor[Lwheel] = 70; (what ever value we determine)

motor[Rwheel] = 70; (what ever value we determine)

wait1Msec(2000); (what ever value we determine)

motor[Lwheel] = 0;

motor[Rwheel] = 0;

wait1Msec(1000)

//clamp

motor[Forklock] = 120; (what ever value we determine)

wait1Msec(1000);

motor[Forklock] =0;

wait1Msec(1000);

//lift

motor[Forklift] = 120;(what ever value we determine)

wait1Msec(1000);

Motor[Forklift] = 0;

wait1Msec(1000);

//reverse

motor[Lwheel] = -70; (what ever value we determine)

motor[Rwheel] = -70; (what ever value we determine)

wait1Msec(2000); (what ever value we determine)

motor[Lwheel] = 0;

motor[Rwheel] = 0;

wait1Msec(500)

Here is our driving code.

image

Code screen shot #2 rest of code.