# Status codes

## Usage

"Command status codes" are additional information you receive with the TotalControl event.


---

## How to get the code

Events come to your script using `link_message`:

```csharp
link_message( integer sender_num, integer num, string str, key id )
```

The **Command status code** is located in the `str` variable (while `num` holds the TotalControl event ID).


---

## Status Codes

The possible status codes are listed below:

| **Possible events** | **Status code** | **Description** |
|-----------------|-------------|-------------|
| **Success code** |             |             |
| `BOT_EVENT_STATUS_REPLY` | OK          | Command succeed, bot subscription valid. |
| **Command fails** |             |             |
| `BOT_COMMAND_FAILED` | UNKNOWN_COMMAND | The command you've sent is unknown. Try upgrading to the most newest version. |
| `BOT_COMMAND_FAILED` | SERVICE_UNAVAILABLE | This SmartBots service is not available for you. Refer to SmartBots Services page for details. |
| `BOT_COMMAND_FAILED`<br>`BOT_SETUP_FAILED`<br>`BOT_EVENT_STATUS_REPLY` | BOT_NOTSET  | You are trying to issue the command, but TotalControl does not know your Bot yet (use [`BOT_SETUP_SETBOT`](/doc/bot_setup_setbot-ojcvi28wUW) command). |
| **Bot status fails** |             |             |
| `BOT_COMMAND_FAILED`<br>`BOT_SETUP_FAILED`<br>`BOT_EVENT_STATUS_REPLY` | BOT_NOTEXIST | The bot you are trying to use does not exist. You have to visit [mysmartbots.com](https://mysmartbots.com) and list your personal bot. |
| `BOT_SETUP_FAILED` | BOT_WRONGCODE | You have specified the wrong Access Code or API token while setting the bot using [`BOT_SETUP_SETBOT`](/doc/bot_setup_setbot-ojcvi28wUW). |
| `BOT_COMMAND_FAILED`<br>`BOT_SETUP_FAILED`<br>`BOT_EVENT_STATUS_REPLY` | BOT_NOTPAID | You've listed your bot with SmartBots, but did not pay your subscription yet. |
| `BOT_COMMAND_FAILED`<br>`BOT_SETUP_FAILED`<br>`BOT_EVENT_STATUS_REPLY` | BOT_EXPIRED | Your SmartBots subscription has expired. The expiration date is attached. |
| `BOT_COMMAND_FAILED`<br>`BOT_SETUP_FAILED`<br>`BOT_EVENT_STATUS_REPLY` | BOT_NOTSETUP | Editor will process and start your order shortly. Please wait a bit. |


---

## Example

The following example shows how to parse a bot setup error.

In this example, we receive the [`BOT_SETUP_FAILED`](/doc/bot_setup_failed-yy58DIzSt3) event — this means that TotalControl can't use the bot you've specified. We should determine what’s wrong (usually an invalid bot name or an expired subscription).

```csharp
link_message(integer sender,integer cmd, string data, key id) {
  /////////////////// Bot setup failed event
  if(cmd==BOT_SETUP_FAILED) {
    // We split the string parameter to the lines
    list parts=llParseString2List(data,["\n"],[]);

    // The first line is a status code, and second line is the bot expiration date
    string code=llList2String(parts,0);
    string expires=llList2String(parts,1);
            
    // Inform user
    llOwnerSay("TotalControl bot setup failed:\n"+
      "error code: "+code+"\n"+
      "expired: "+expires);
  }
}
```