Difference between revisions of "ListItemReplace"

From Second Life Wiki
Jump to navigation Jump to search
m (<lsl> tag to <source>)
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{LSL Header}} __NOTOC__
{{LSL Header}} __NOTOC__
[[Category:LSL_User-Defined Functions]]
<div id="box">
<div id="box">
== Function: [[list]] ListItemReplace([[list]] {{LSL Param|mylist}}, [[string]] {{LSL Param|element_old}},[[string]] {{LSL Param|element_new}} ); ==
== Function: [[list]] ListItemReplace([[list]] {{LSL Param|mylist}}, [[string]] {{LSL Param|element_old}},[[string]] {{LSL Param|element_new}} ); ==
Line 7: Line 8:
See also: [[List|Lists]]
See also: [[List|Lists]]


<lsl>
<source lang="lsl2">
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]);
Line 13: Line 14:
         return llListReplaceList(mylist, [element_new], placeinlist, placeinlist);     
         return llListReplaceList(mylist, [element_new], placeinlist, placeinlist);     
     }
     }
     llSay(0, "ERROR: Element '" + element_old + "' not found in list [" + llList2CSV(mylist) + "]" );
     llOwnerSay("ERROR: Element '" + element_old + "' not found in list [" + llList2CSV(mylist) + "]" );
     return mylist;
     return mylist;
}
}
</lsl>
</source>




list myupdatedList = ListItemReplace(mylist,"Brown","Blue");
<source lang="lsl2">list myupdatedList = ListItemReplace(mylist,"Brown","Blue");</source>





Latest revision as of 14:20, 22 January 2015

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

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);    
    }
    llOwnerSay("ERROR: Element '" + element_old + "' not found in list [" + llList2CSV(mylist) + "]" );
    return mylist;
}


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