SLUDGE

cancelSub


Syntax:

cancelSub (thisFunction);

Purpose:

Cancels any instances of thisFunction which are running.

This command will only cancel a function which has been paused by either the pause or one of the say and think commands, and will not cancel a function which is temporarily inactive because of a call to another user-defined function. For example:

sub outer () {
   loop {
      say (a, "Outer.");
      inner ();
   }
}

sub inner () {
   say (a, "Inner.");
}

sub clicky () {
   cancelSub (outer);
}

sub init () {
   spawnSub (outer);
   onLeftMouse (clicky);
}

In the above example, pressing the left mouse button will only cancel the loop if the character a is saying "Outer" and not "Inner"; i.e. while the outer function is active.

The cancelSub command will also not cancel a function which is suspended because of a character which is currently moving (because of a call to either the moveCharacter or forceCharacter function). In these situations you can use stopCharacter to stop the character in its tracks, automatically cancelling the suspended function. Several other commands will also stop the movement of the character, thereby cancelling the function which was suspended because the character was moving.

Return value:

This function returns the number of instances of thisFunction which were cancelled.

Example:

sub speechFunction () {
   loop {
      say (someCharacter, "And so I said to her...");
      say (someCharacter, "Blah blah blah blah blah...");
      say (someCharacter, "Pom-pa-pom-pa-pom...");
      say (someCharacter, "And then she said...");
      say (someCharacter, "Rhubarb rhubarb rhubarb...");
      say (someCharacter, "Yada yada yada...");
   }
}

sub clicky () {
   cancelSub (speechFunction);
   say (ego, "Oh, do shut up.");
   say (someCharacter, "Pardon me for breathing.");
}

sub init () {
   spawnSub (speechFunction);
   onLeftMouse (clicky);
}

See also:

spawnSub