|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +author: missyrestless |
| 4 | +title: LifeBots Control Panel Example - Avatar Picks |
| 5 | +description: Example LifeBots Control Panel user script to display an avatar's profile picks when touched |
| 6 | +category: [ControlPanel] |
| 7 | +tag: [lifebots, controlpanel, examples] |
| 8 | +pin: false |
| 9 | +date: 2026-03-30 11:31 -0700 |
| 10 | +--- |
| 11 | + |
| 12 | +The `LifeBots Control Panel` acts as a bridge between your user script and the `LifeBots` API. |
| 13 | +In order for the Control Panel to execute requests to the `LifeBots` API, a LifeBots API Key and |
| 14 | +Bot Access Secret (aka Code) are required. |
| 15 | + |
| 16 | +Before you begin the setup process, generate and copy your LifeBots API Key and your bot's access secret: |
| 17 | + |
| 18 | +- Visit the [LifeBots Developer Hub](https://lifebots.cloud/developer) to generate and copy your LifeBots API Key |
| 19 | +- See the LifeBots Knowledge Base article on [How to Setup a Bot Access Secret](https://lifebots.cloud/support/article/how-to-setup-a-bot-access-secret) |
| 20 | + |
| 21 | +## Setup instructions for the Avatar Picks LifeBots Control Panel Example |
| 22 | + |
| 23 | +To setup the Avatar Picks LifeBots Control Panel Example: |
| 24 | + |
| 25 | +- Rez the `LifeBots Control Panel` object in-world |
| 26 | +- Right click the rezzed control panel and select Edit |
| 27 | +- In the Content tab of the Edit window right click the Configuration notecard and select Open |
| 28 | +- Configure the `LifeBots Control Panel` with your LifeBots API Key |
| 29 | + - On the line `LB_API_KEY = your-api-key` replace `your-api-key` with your LifeBots API Key |
| 30 | + - Save and close the `Configuration` notecard |
| 31 | +- Drag and Drop the `AvatarPicksConf` notecard from your inventory into the Content tab of the object |
| 32 | +- In the Content tab of the Edit window right click the `AvatarPicksConf` notecard and select Open |
| 33 | + - On the line `LB_BOT_NAME = Bot Name` replace `Bot Name` with your LifeBots bot name |
| 34 | + - On the line `LB_BOT_CODE = Bot Access Code` replace `Bot Access Code` with your LifeBots bot access code |
| 35 | + - Save and close the `AvatarPicksConf` notecard |
| 36 | +- Drag and Drop the `avatar_picks` script from your inventory into the Content tab of the object |
| 37 | +- Right click the control panel object and select 'More' -> 'More' -> 'Scripts' -> 'Reset Scripts' |
| 38 | + |
| 39 | +Once configured the Control Panel should display the Profile Picks of the avatar that touches it. |
| 40 | + |
| 41 | +Contact Missy Restless in-world or email missyrestless@gmail.com with questions, comments, and suggestions. |
| 42 | + |
| 43 | +## Avatar Picks Example AvatarPicksConf Notecard |
| 44 | + |
| 45 | +The `AvatarPicksConf` notecard contains the following: |
| 46 | + |
| 47 | +```sh |
| 48 | +# Uncomment to enable debug mode |
| 49 | +#DEBUG = TRUE |
| 50 | +# LifeBots Bot Name REQUIRED |
| 51 | +# DO NOT surround the Bot Name with single or double quotes |
| 52 | +LB_BOT_NAME = Bot Name |
| 53 | +# LifeBots Bot Access Code REQUIRED |
| 54 | +# DO NOT surround the Bot Code with single or double quotes |
| 55 | +LB_BOT_CODE = Bot Access Code |
| 56 | +# DO NOT remove END_SETTINGS line |
| 57 | +END_SETTINGS |
| 58 | +# The settings prior to END_SETTINGS are all that is read and used. |
| 59 | +``` |
| 60 | + |
| 61 | +## Avatar Picks Example avatar_picks Script |
| 62 | + |
| 63 | +The `avatar_picks` script contains the following: |
| 64 | + |
| 65 | +```lsl |
| 66 | +//////////////////////////////////////////////////////////////////////////////// |
| 67 | +// Avatar Picks - returns the Profile Picks of whoever touches the object // |
| 68 | +// Control Panel documentation: https://slbotcontrol.github.io/control_panel/ // |
| 69 | +//////////////////////////////////////////////////////////////////////////////// |
| 70 | +// |
| 71 | +/////////////////////////////////////////////////////// |
| 72 | +// Copyright (c) 2026 Truth & Beauty Lab // |
| 73 | +// Author: Missy Restless <missyrestless@gmail.com> // |
| 74 | +// Created: 29-Mar-2026 // |
| 75 | +// License: MIT // |
| 76 | +/////////////////////////////////////////////////////// |
| 77 | +// |
| 78 | +string deviceName = "Avatar Picks"; |
| 79 | +string botName = ""; |
| 80 | +string botCode = ""; |
| 81 | +// Set DEBUG to 1 to enable debug output |
| 82 | +integer DEBUG = 0; |
| 83 | +
|
| 84 | +//////// LIFEBOTS COMMAND & CONTROL CODES //////// |
| 85 | +integer AVATAR_PICKS = 299024; // |
| 86 | +integer BOT_RESPONSE = 300000; // |
| 87 | +integer BOT_SETUP_DEVICENAME = 280103; // |
| 88 | +integer BOT_SETUP_SETBOT = 280101; // |
| 89 | +integer BOT_SETUP_SUCCESS = 280201; // |
| 90 | +integer BOT_SETUP_FAILED = 280202; // |
| 91 | +integer BOT_SETUP_DEBUG = 280105; // |
| 92 | +integer BOT_SETUP_DEBUG_SUCCESS = 280107; // |
| 93 | +integer BOT_SETUP_RETRY = 300002; // |
| 94 | +////////////////////////////////////////////////// |
| 95 | +
|
| 96 | +//////////////////////////////////////////////////// |
| 97 | +// Get Avatar Profile Picks |
| 98 | +//////////////////////////////////////////////////// |
| 99 | +key touchUUID = NULL_KEY; |
| 100 | +
|
| 101 | +// Number of retries waiting for Control Panel to initialize |
| 102 | +integer retries = 0; |
| 103 | +
|
| 104 | +// Configuration Notecard |
| 105 | +string CONFIG_CARD = "AvatarPicksConf"; |
| 106 | +integer NotecardLine; |
| 107 | +integer NotecardDone = 0; |
| 108 | +key QueryID; |
| 109 | +
|
| 110 | +bot_code_not_set() { |
| 111 | + llOwnerSay("ERROR: LB_BOT_CODE not set."); |
| 112 | + llOwnerSay("Edit the AvatarPicksConf notecard to set your LifeBots Bot Access Code."); |
| 113 | +} |
| 114 | +
|
| 115 | +bot_name_not_set() { |
| 116 | + llOwnerSay("ERROR: LB_BOT_NAME not set."); |
| 117 | + llOwnerSay("Edit the AvatarPicksConf notecard to set your LifeBots Bot Name."); |
| 118 | +} |
| 119 | + |
| 120 | +default { |
| 121 | + state_entry() |
| 122 | + { |
| 123 | + llOwnerSay("Starting up LifeBots Control Panel Avatar Picks script..."); |
| 124 | + if (llGetInventoryType(CONFIG_CARD) == INVENTORY_NOTECARD) { |
| 125 | + NotecardLine = 0; |
| 126 | + QueryID = llGetNotecardLine(CONFIG_CARD, NotecardLine); |
| 127 | + } else { |
| 128 | + llOwnerSay("ERROR: " + CONFIG_CARD + " notecard not found!"); |
| 129 | + } |
| 130 | + } |
| 131 | +
|
| 132 | + dataserver( key queryid, string data ) |
| 133 | + { |
| 134 | + list temp; |
| 135 | + string name; |
| 136 | + string value; |
| 137 | + if ( queryid == QueryID ) { |
| 138 | + if ((NotecardDone == 0) && (data != EOF)) { |
| 139 | + if (data == "END_SETTINGS") { |
| 140 | + NotecardDone = 1; |
| 141 | + if ((botCode == "") || (botCode == "Bot Access Code")) { |
| 142 | + bot_code_not_set(); |
| 143 | + } else { |
| 144 | + if ((botName == "") || (botName == "Bot Name")) { |
| 145 | + bot_name_not_set(); |
| 146 | + } else { |
| 147 | + // Setup Device and Bot using linked messages |
| 148 | + llMessageLinked(LINK_SET, BOT_SETUP_DEVICENAME, deviceName, llGetOwner()); |
| 149 | + llMessageLinked(LINK_SET, BOT_SETUP_SETBOT, botName, botCode); |
| 150 | + } |
| 151 | + } |
| 152 | + } else if ( llGetSubString(data, 0, 0) != "#" && llStringTrim(data, STRING_TRIM) != "" ) { |
| 153 | + temp = llParseString2List(data, ["="], []); |
| 154 | + name = llStringTrim(llList2String(temp, 0), STRING_TRIM); |
| 155 | + value = llStringTrim(llList2String(temp, 1), STRING_TRIM); |
| 156 | + if ( value == "TRUE" ) value = "1"; |
| 157 | + if ( value == "FALSE" ) value = "0"; |
| 158 | + if ( name == "LB_BOT_CODE" ) { |
| 159 | + if (DEBUG == 1) { |
| 160 | + llSay(DEBUG_CHANNEL, "Setting Bot Code to " + value); |
| 161 | + } |
| 162 | + botCode = value; |
| 163 | + } else if ( name == "LB_BOT_NAME" ) { |
| 164 | + if (DEBUG == 1) { |
| 165 | + llSay(DEBUG_CHANNEL, "Setting Bot Name to " + value); |
| 166 | + } |
| 167 | + botName = value; |
| 168 | + } else if ( name == "DEBUG" ) { |
| 169 | + DEBUG = (integer)value; |
| 170 | + } |
| 171 | + } |
| 172 | + NotecardLine++; |
| 173 | + QueryID = llGetNotecardLine( CONFIG_CARD, NotecardLine ); |
| 174 | + } else { |
| 175 | + NotecardLine = 0; |
| 176 | + } |
| 177 | + } |
| 178 | + } |
| 179 | +
|
| 180 | + on_rez(integer param) |
| 181 | + { |
| 182 | + llResetScript(); |
| 183 | + } |
| 184 | +
|
| 185 | + changed(integer change) |
| 186 | + { |
| 187 | + if (change & (CHANGED_OWNER | CHANGED_INVENTORY)) |
| 188 | + { |
| 189 | + llResetScript(); |
| 190 | + } |
| 191 | + } |
| 192 | + |
| 193 | + // Get avatar profile picks on touch |
| 194 | + touch_start(integer num) { |
| 195 | + touchUUID = llDetectedKey(0); |
| 196 | + llMessageLinked(LINK_SET, AVATAR_PICKS, "", touchUUID); |
| 197 | + } |
| 198 | + |
| 199 | + // Notify owner if device was successfully initialized |
| 200 | + link_message( integer sender_num, integer num, string str, key id ) { |
| 201 | + /////////////////// Bot setup success event |
| 202 | + if (num == BOT_SETUP_SUCCESS) { |
| 203 | + llOwnerSay("Successfully setup bot: " + str); |
| 204 | + retries = 0; |
| 205 | +
|
| 206 | + if (DEBUG == 1) { |
| 207 | + llMessageLinked(LINK_SET, BOT_SETUP_DEBUG, "1", ""); |
| 208 | + } |
| 209 | + } else if (num==BOT_SETUP_RETRY) { |
| 210 | + if (retries > 12) { |
| 211 | + llOwnerSay("Unable to setup bot"); |
| 212 | + retries = 0; |
| 213 | + } else { |
| 214 | + llOwnerSay("LifeBots Control Panel is not yet initialized, trying again in 5 seconds..."); |
| 215 | + retries++; |
| 216 | + llSleep(5.0); |
| 217 | + llMessageLinked(LINK_SET, BOT_SETUP_SETBOT, botName, botCode); |
| 218 | + } |
| 219 | + } else if (num == BOT_SETUP_FAILED) { |
| 220 | + retries = 0; |
| 221 | + // We split the string parameter to the lines |
| 222 | + list parts=llParseString2List(str,["\n"],[]); |
| 223 | +
|
| 224 | + // The first line is a status code, and second line is the bot expiration date |
| 225 | + string code=llList2String(parts,0); |
| 226 | + string expires=llList2String(parts,1); |
| 227 | + |
| 228 | + // Setup failed somehow |
| 229 | + llOwnerSay("Bot setup failed:\n"+ |
| 230 | + "error code: "+code+"\n"+ |
| 231 | + "expired: "+expires); |
| 232 | + } else if (num == BOT_RESPONSE) { |
| 233 | + string displayName = llGetDisplayName(touchUUID); |
| 234 | + if (llJsonGetValue(str, ["picks"]) == JSON_INVALID) { |
| 235 | + llSay(0, displayName + " profile picks:\n" + str); |
| 236 | + } else { |
| 237 | + llSay(0, displayName + " profile picks:\n" + llJsonGetValue(str, ["picks"])); |
| 238 | + } |
| 239 | + } else if (num==BOT_SETUP_DEBUG_SUCCESS) { |
| 240 | + llOwnerSay("Avatar Picks Debug Setup Success"); |
| 241 | + } |
| 242 | + } |
| 243 | +} |
| 244 | +``` |
0 commit comments