PauseTask() - The Pause Task Command

The PauseTask() command pauses one or more tasks on the same device.
A task cannot be started if it is already running but it can be paused and the resume from where it left off using the StartTask() command.
While paused you can use the StopTask() or CancelTask() commands to end the task so the next StartTask() command will start from the beginning.
This can be useful if you want another task to process some data or to pause a looping tasking like a chase.

Syntax

Basic Use PauseTask(x)
Where "x" is the task you want to pause.
Can be any value 1-254 or "ALL" to pause all tasks at once.

Advanced Use PauseTask(x,y,z,…​n)
This allows you to pause multiple tasks with a single command. However, this technique will only work with tasks numbered 16 or less. To pause a higher numbered task you must use the basic version.

Examples

Example 1

A basic use of the command to pause a single task.

{
   Start(0x1c,250,x,x,x,x,x)//Watches all 1C messages for our trigger area.
	copy @0,~0,7			//Copy the msg to ~0-6.  ~1 is area, ~3 is preset.
	LDA ~3					//Get preset byte (opcode)
	CMP #0x00			    //Is it a message for preset 1?
	BRZ P1				    //If it matches branch.  If not continue.
	CMP #0x01			    //Is it a message for Preset 2?
	BRZ P2  				//
    CMP #0x02			    //Is it a message for Preset 3?
	BRZ P3  				//
    CMP #0x03			    //Is it a message for Preset 4?
	BRZ P4
	Null					//Stop.  Do not pass go.  Do not collect $200.
	P1:
        StopTask(3)         //Stop the rainbow chase task.
        StartTask(2)        //Start the color fade task.
        Null
	P2:
        StopTask(2)         //Stop the colorfade task.
        StartTask(3)        //Start the rainbow chase task.
        Null
    P3:                     //Pause all chases at current step.
        PauseTask(2)        //Pause the colorfade task.
        PauseTask(3)        //Pause the rainbow chase task.
        Null
    P4:                     //Stop all chases
        StopTask(2)         //Stop the colorfade task.
        StopTask(3)         //Stop the rainbow chase task.
        Null
}

Example 2

Advanced use of the command to pause multiple tasks.

{
PauseTask(2,3,5,9,16)       //Pause tasks 2, 3, 5, 9, 16
PauseTask(22)               //Pause task 22 by itself because it is bigger than 16
}

Example 3

A basic use of the command to pause a single task.
This task excerpt loads preset values into a buffer and then the task starts another task to process the data and pauses itself. The processing task resumes this task after it finishes.

{
    ...
ColorLoop:
		LDA #P2OpCode		//Load the opcode
		STA TXPresetByte    //Store into the message buffer.
		StartTask(11)		//Start the Send Task
		PauseTask(10)		//Pause this task and wait for the TX to restart it.

		LDA #P3OpCode		//Load the opcode
		STA TXPresetByte	//Store into the message buffer.
		StartTask(11)	    //Start the Send Task
		PauseTask(10)		//Pause this task and wait for the TX to restart it.
        ...
}

Example 4

The Kill Switch.

{
Start(0x1c,16,x,17,x,x,x)	//Starts on a panic for the baselink area
PauseTask(All)              //Pauses all tasks
}