Slay

(Engine-Level Function)

Description: Stops a launched module, and possibly any parent modules.
Returns: Nothing
Usage: Script Only.
Function Groups: Basic Module
Related to: Stop | WindowClose
Format: Slay([Object, KillParents])
Parameters:  
Object
An optional parameter which is any object expression for the launched module. The default value of Object is Self().
KillParents
An optional logical expression for the action to take. If true, Slay will attempt to stop parents as well. It will step through and slay each parent object until it encounters a parent object that is a called object. It will not slay that object or any of that object's parents. The default value for KillParents is FALSE.
Comments: If Object is in the middle of executing script, it is immediately stopped. Slay and Return are the only statements that will cause a script to terminate mid-way through its execution. Others like ForceState will not.
Slay() is the same as Slay(Self(), FALSE).

Example:

  If ZButton(20, 50, 120, 70, "Motor On/Off", 1);
  [
    IfElse(!MotorOn, Execute(
            MotorOn = 1;
            MotorPtr = RunMotor() { Module launched implicitly };
    );
    { else } Execute(
            MotorOn = 0;
            Slay(MotorPtr, 0);
    ));
  ]

When the button is selected, the statement in the script will check if the motor is running or not, and if it isn't, will launch the module that starts it. Notice that the module is launched implicitly because it is called from inside of a script. If that module is already running it will stopped by the Slay .