# llGetScriptState

*LSL function*

```lsl
integer integer llGetScriptState(string script);
```

- `string script`: Name of the script in the prim's inventory.

- Returns: `integer`
- Energy: 10

Returns a boolean integer indicating whether the specified script in the prim's inventory is running (returns TRUE if running, FALSE otherwise).

Returns an [integer](https://wiki.secondlife.com/wiki/integer) that is [TRUE](/constants/TRUE/) if the **script** is running.

```lsl title="How to use" frame="terminal"
integer result = llGetScriptState("");
```

## Examples

<details open>
<summary>Example 1</summary>

```lsl collapse={1-8, 14-24}
default
{
    touch_start(integer num_detected)
    {
        integer numberOfScripts = llGetInventoryNumber(INVENTORY_SCRIPT);

        integer index;
        do
        {
            string scriptName = llGetInventoryName(INVENTORY_SCRIPT, index);
            integer scriptState = llGetScriptState(scriptName);

        //  default value
            string output = "FALSE";
        //  else
            if (scriptState) output = "TRUE";

            // PUBLIC_CHANNEL has the integer value 0
            llSay(PUBLIC_CHANNEL,
                "Script named '" + scriptName + "' has current script state '" + output + "'.");
        }
        while (++index < numberOfScripts);
    }
}
```

</details>

<details>
<summary>Example 2</summary>

```lsl collapse={1-18, 29-35}
// Monitor other scripts in the object, then report, restart or both if some have crashed
// NB: cannot distinguish a manually stopped script or restart one
integer TRY_RESTART = FALSE;
integer REPORT = TRUE;

default
{
    state_entry() {
        // monitoring rate = once per minute
        llSetTimerEvent(60);
    }

    timer() {
        integer i = llGetInventoryNumber(INVENTORY_SCRIPT);
        string script_name;
        list stopped;

        while(--i >= 0) {
            // the script will also monitor itself, but there is little reason to specifically skip
            script_name = llGetInventoryName(INVENTORY_SCRIPT, i);
            if(!llGetScriptState(script_name)) {
                if(TRY_RESTART)
                    llResetOtherScript(script_name);
                if(REPORT)
                    stopped += script_name;
            }
        }
        if(stopped) {
            string message = "The following scripts were crashed/stopped: " + llList2CSV(stopped) + ".";
            if(TRY_RESTART)
                message += " A restart was attempted.";
            llInstantMessage(llGetOwner(), message);
        }
    }
}
```

</details>

## History

- There was a time when [llGetScriptState](/functions/llGetScriptState/) would return [TRUE](/constants/TRUE/) even if the script had encountered a [run-time error](https://wiki.secondlife.com/wiki/Category:LSL_Error). This is no longer the case.

## See also

### Functions

- [llSetScriptState](/functions/llSetScriptState/)
- [llResetOtherScript](/functions/llResetOtherScript/)

---

*Source: [LlGetScriptState](https://wiki.secondlife.com/wiki/LlGetScriptState) on the Second Life Wiki. Content from the Second Life Wiki articles LlGetScriptState (revision 1215122, 2023-10-18) and Template:LSL Function/inventory (revision 1191151, 2014-06-07), CC BY-SA 3.0.*

---

From lsl.dev: https://lsl.dev/functions/llGetScriptState/
