Difference between revisions of "HTTP API/Examples/Get bot status"

From SmartBots Developers Docs
Jump to: navigation, search
(Created page with "{{DISPLAYTITLE:{{SUBPAGENAME}}}} <onlyinclude> This script requests bot status and displays it. Place this code to an in-world object, and replace variables at the beginning...")
 
Line 7: Line 7:
 
=== LSL Code ===
 
=== LSL Code ===
  
'''IMPORTANT!''' Paste SmartBots [[/HTTP API/LSL Helper Functions|LSL Helper Functions]] (smartbotsAPI/smartbotsAPIJSON) before saving.
+
'''IMPORTANT!''' Paste SmartBots [[HTTP API/LSL Helper Functions|LSL Helper Functions]] (smartbotsAPI/smartbotsAPIJSON) before saving.
  
 
<syntaxhighlight lang="lsl">
 
<syntaxhighlight lang="lsl">

Revision as of 14:37, 14 October 2019


This script requests bot status and displays it.

Place this code to an in-world object, and replace variables at the beginning with your values (read more about api key and Bot access code);

LSL Code

IMPORTANT! Paste SmartBots LSL Helper Functions (smartbotsAPI/smartbotsAPIJSON) before saving.

// Paste SmartBots LSL Helper Functions here

default {
    state_entry() {
        llOwnerSay("Script initialized");
    }

    touch_start(integer total_number) {
        llOwnerSay("Requesting bot status...");
        smartbotsAPIJSON("status", []);
    }
    
    // Get the SmartBots API reply
    http_response(key request_id, integer status, list metadata, string body) {
        // llOwnerSay("API raw response: " + body);
        
        string status = llJsonGetValue(body, ["status"]);
        string slname = llJsonGetValue(body, ["slname"]);
        string uuid = llJsonGetValue(body, ["uuid"]);
        string location = llJsonGetValue(body, ["location"]);
        
        llOwnerSay("Bot status:\n" + 
            "name: " + slname + " / " + uuid + "\n" +
            "online status: " + status + "\n" +
            "location: " + location
        );
    }
}