Putting StopTask in a Task

I was wondering if you could put the StopTask command inside of the Task itself. For example:

task example
{
motor[m1] = 100;
wait1Msec(1000);

StopTask( example );
}

task main
{
StartTask( example) ;

motor[m2] = 100;
wait1Msec(1000);
}

Would it do task example once and then move on to motor m2? I would test it myself but currently I don’t have a robot on me.

Yes it would. But you can achieve the same thing (without stoptask) if you used voids.

Please tell me how to do it with voids! I’ve been trying to figure out how for a while now.

you can replace the task with a void, a void would only run once, (it wouldn’t really make a difference in this scenario cause you don’t have a loop).

i was wrong in my previous statement, what would actually happen is, it would start your task and run both at the same time (multi-tasking) to achieve what you are looking for, you would use voids. a void pauses your current task, runs the code inside the void, and resumes code once the void is finished. your code would look like this


void example()
{
motor[m1] = 100;
wait1Msec(1000);
}

task main
{
example();

motor[m2] = 100;
wait1Msec(1000);
}

Oops I actually phrased my original question wrong. What I wanted to do was make the two motors start at the same time and then end at different times. I actually was able to test it (I used a few spare motors and a random cortex lying around) and it did achieve what I was looking for.

Have a read of this as well.
https://vexforum.com/t/robotc-bad-programming-habits/28357/1

Can we add to that list calling functions “voids”

To be clear, tasks are started them skipped, so it would start the next part of the program without waiting for the task to end.

I second that.

This is something I need to read hangs head