Get bot status

From SmartBots Developers Docs
HTTP APIExamples
Revision as of 14:37, 14 October 2019 by Gg (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


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
        );
    }
}