Primitive Name Changer

From Second Life Wiki
Jump to: navigation, search

Created by Kira Komarov for Elizabeth Tinsley.

Introduction

This is a simple script that changes the name of the primitive it is in after a certain configurable interval.

Setup

  • Create a notecard called Names and list the names that the primitive should take line-by-line.
  • Drop the notecard Names into a primitive.
  • Create a script in the same primitive where you put the notecard Names and copy and paste the code below.
  • Optionally, configure the NAME_CHANGE_INTERVAL and set it to the interval between renames.

Code

//////////////////////////////////////////////////////////
// [K] Kira Komarov - 2011, License: GPLv3              //
// Please see: http://www.gnu.org/licenses/gpl.html     //
// for legal details, rights of fair usage and          //
// the disclaimer and warranty conditions.              //
//////////////////////////////////////////////////////////
 
//////////////////////////////////////////////////////////
//                   CONFIGURATION                      //
//////////////////////////////////////////////////////////
 
// Set this to the amount of time before the script 
// changes the name of the primitive.
 
integer NAME_CHANGE_INTERVAL = 1;
 
//////////////////////////////////////////////////////////
//                     INTERNALS                        //
//////////////////////////////////////////////////////////
key qQuery;
integer qLine;
list qList = [];
 
integer comHandle;
 
default
{
    state_entry()
    {
        integer itra;
        for(itra=0, qList=[], qLine=0; itra<llGetInventoryNumber(INVENTORY_NOTECARD); ++itra) {
            if(llGetInventoryName(INVENTORY_NOTECARD, itra) == "Names")
                jump found_quotes;
        }
        llOwnerSay("Names notecard not found, please add a notecard called Names and list all the names line by line making sure that you have a blank line at the end.");
        return;
@found_quotes;
        qQuery = llGetNotecardLine("Names", qLine);
    }
 
    changed(integer change) {
        if(change & CHANGED_INVENTORY) {
            llResetScript();
        }
    }
 
    timer() {
        llSetTimerEvent(0);
        string name = llList2String((qList = llDeleteSubList((qList = []) + qList, 0, 0)), 0);
        llSetObjectName(name);
        qList += name;
        llSetTimerEvent(NAME_CHANGE_INTERVAL);
    }
 
    dataserver(key id, string data) {
        if(id != qQuery) return;
        if(data == EOF) {
            if(!llGetListLength(qList)) {
                llOwnerSay("The Name notecard is empty, please add some names and make sure you have a blank line at the end.");
                return;
            }
            llOwnerSay("List read, setting object name in " + (string)NAME_CHANGE_INTERVAL + "s intervals.");
            llSetTimerEvent(NAME_CHANGE_INTERVAL);
            return;
        }
        if(data == "") jump next_line;
        qList += data;
@next_line;
        qQuery = llGetNotecardLine("Names", ++qLine);
    }
}