Difference between revisions of "ListItemReplace"

From Second Life Wiki
Jump to: navigation, search
(New page: {{LSL Header}} __NOTOC__ <div id="box"> == Function: list ListItemReplace(list {{LSL Param|mylist}}, string {{LSL Param|element_old}},string {{LSL Param|element_new}} ); ==...)
 
Line 10: Line 10:
 
list ListItemReplace(list mylist,string element_old, string element_new) {
 
list ListItemReplace(list mylist,string element_old, string element_new) {
 
     integer placeinlist = llListFindList(mylist, [element_old]);
 
     integer placeinlist = llListFindList(mylist, [element_old]);
     list newlist = llListReplaceList(mylist, [element_new], placeinlist, placeinlist);
+
     if ( placeinlist != -1 ) {
     return newlist;
+
        return llListReplaceList(mylist, [element_new], placeinlist, placeinlist);   
 +
    }
 +
    llSay(0, "ERROR: Element '" + element_old + "' not found in list");
 +
     return mylist;
 
}
 
}
 
</lsl>
 
</lsl>

Revision as of 10:35, 26 September 2009

Function: list ListItemReplace(list mylist, string element_old,string element_new );

Replaces a single occurrence of something in a list with something else that you specify.

See also: Lists

<lsl> list ListItemReplace(list mylist,string element_old, string element_new) {

   integer placeinlist = llListFindList(mylist, [element_old]);
   if ( placeinlist != -1 ) {
       return llListReplaceList(mylist, [element_new], placeinlist, placeinlist);    
   }
   llSay(0, "ERROR: Element '" + element_old + "' not found in list");
   return mylist;

} </lsl>


list myupdatedList = ListItemReplace(mylist,"Brown","Blue");