Create a Task

Is there a way to create tasks in robot c graphical

To my knowledge, no. Try this program though, it may work as I have modified it manually as a text file. Change the file extension to .rbg and see if it works.

I changed the code without changing the blocks.
Graphical002.vex (3.63 KB)

Not sure how the variable (code above) would work. I am trying to make an e-stop task button that would run inside of a program. Task would look like this:

Create a task called e-stop (if button pressed stop all tasks)

Then write a program to do what our program would do, but inside of the program there would be a line at the start of the program that would say start e-stop. if the button were pressed it would start the e-stop.

How would I do this below (In RobotC Graphical)

task e_stop()
{
while(true)
{
if(SensorValue(e_stopBtn) == 1)
{
stopAllTasks(); // ends the program and all tasks including task main.
}
wait1Msec(10); // prevents the current task from using majority of available CPU capacity
}
}

task main()
{
startTask(e_stop); // initiates the e-stop task which will run simultaneously
while(true)
{
if(SensorValue(sonar) <= 10)
{
motor[rightMotor] = 32;
motor[leftMotor] = -32;
}
else
{
motor[rightMotor] = 127;
motor[leftMotor] = -127;
}
wait1Msec(10); // prevents the current task from using majority of available CPU capacity
}
}

Vex IQ had a topic related to this: RE: ROBOTC Graphical Multitasking - VIQC Ringmaster (2017-2018 Game) - VEX Forum

There really is no need for all that complexity. You have a single while(true) loop for the main code. Just check inside that loop and change while(true). For example,

bool eStop = false;

task main() {
   while(eStop != true){
      if(SensorValue(sonar) <= 10) {
         motor[rightMotor] = 32;
         motor[leftMotor] = -32;
      }
      else {
         motor[rightMotor] = 127;
         motor[leftMotor] = -127;
      }
      if(SensorValue(e_stopBtn) == 1) {
         eStop = true;
      }
      wait1Msec(10);
   }
}