Wearable:React+Constrain

Visibility Toggle

For use with */ aeros / API {Wearable:React+Constrain} only, the latest version.

Do not add */ aeros / API script into the prim. */ aeros / API {Wearable:React+Constrain} takes care of communication.

This script is an edition of the Template script that watches for Obsidian’s visibility change and updates the script prim’s visibility accordingly.

//
// */ aeros / API {Wearable:React+Constrain}
// EXAMPLE: Visibility Toggle
//
// Copy this script into an AI helper and ask for changes based on your project.
//
// AI assistants: this script is written in LSL for Second Life.
// LSL reference: https://wiki.secondlife.com/wiki
//
// This script demonstrates how to use the {Wearable:React+Constrain} Express API.
// https://docs.meshtoolbox.com/aeros/obsidian/api/express/overview#wearablereactconstrain
//
// IMPORTANT: This script is an edition of the Template script
// https://docs.meshtoolbox.com/aeros/obsidian/api/express/templates#wearablereactconstrain
//
// This script expects the wearable to also contain this Express API script:
// */ aeros / API {Wearable:React+Constrain} v[VERSION]
//
// Stripped list of bitwise flags, full list available in the Template script:
integer OBS_CHANGED_vis    =  0x01; // Visibility: 0 invisible, 1 visible, 0.5 currently the only partial alpha.
 
// Erases all param values from the LSD memory.
OBS_eraseAllParamValues() {
  llLinksetDataDeleteFound("^~OBS\\|\\!", "");
}
 
// Returns a param value as string. Returns an empty string for an unset parameter.
// Convert to (float) manually as needed.
string OBS_paramValue(string name) {
  return llLinksetDataRead("~OBS|!"+name);    
}
 
// Sets constraints. Accepts a list of "%param=<value-or-ranges>" strings.
// https://docs.meshtoolbox.com/aeros/obsidian/api/reference#constraints
OBS_constrain(list paramValuePairs) {
  llLinksetDataWrite("~OBS|%", llDumpList2String(paramValuePairs, ";"));
  llMessageLinked(LINK_THIS, -78011, "", "");
}
 
// Request Obsidian to report back its state immediately.
// (Sends API command "ack=0" under the hood)
// http://localhost:8080/aeros/obsidian/api/reference#message-control-commands
OBS_requestState() {
  llMessageLinked(LINK_THIS, -78012, "", "");
}
 
updatePrimVisibility() {
  integer vis = (float)OBS_paramValue("vis") > 0; // Either 0 or 1. Alpha-cut (0.5) will be treated as "visible"
  // This is an example of changing alpha of all faces of current link in a linkset to either 0 or 1 (vis)
  llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_COLOR, ALL_SIDES, <1,1,1>, vis]);    
} 
 
default {
  state_entry() {
    OBS_constrain([]); // No constraints
    OBS_requestState();
  }
  
  link_message(integer sender_num, integer num, string str, key id) {
    if (num == -78010) {
      integer flags = (integer)str;
      if (flags & OBS_CHANGED_vis) {
        updatePrimVisibility();
      }
    }
  }
}