Difference between revisions of "ListItemDelete"

From Second Life Wiki
Jump to navigation Jump to search
m (<lsl> tag to <source>)
 
(4 intermediate revisions by 3 users not shown)
Line 3: Line 3:
|mode=user
|mode=user
|p1_type=list|p1_name=mylist|p1_desc=list to remove items from
|p1_type=list|p1_name=mylist|p1_desc=list to remove items from
|p2_type=list|p2_name=element|p2_desc=item to remove from '''mylist'''
|p2_type=string|p2_name=element|p2_desc=item to remove from '''mylist'''
|return_type=list
|return_type=list
|return_text=that is a copy of '''mylist''' but with the first instance of '''element''' removed.
|return_text=that is a copy of '''mylist''' but with the first instance of '''element''' removed.
|func_footnote=
|func_footnote=
See also: [[List|Lists]]
See also: [[List|Lists]]
|spec=<lsl>list ListItemDelete(list mylist,string element_old) {
|spec=<source lang="lsl2">list ListItemDelete(list mylist,string element_old) {
     integer placeinlist = llListFindList(mylist, [element_old]);
     integer placeinlist = llListFindList(mylist, [element_old]);
     if (placeinlist != -1)
     if (placeinlist != -1)
         return llDeleteSubList(mylist, placeinlist, placeinlist);
         return llDeleteSubList(mylist, placeinlist, placeinlist);
     return mylist;
     return mylist;
}</lsl>
}</source>
|caveats
|caveats
|examples=<lsl>
|examples=<source lang="lsl2">
list mylist = ["Red", "Green", "Blue", "Brown"];
list mylist = ["Red", "Green", "Blue", "Brown"];
list myShortenedList = ListItemDelete(mylist, ["Brown"]);
list myShortenedList = ListItemDelete(mylist, "Brown");
//myShortenedList is now ["Red", "Green", "Blue"]</lsl>
//myShortenedList is now ["Red", "Green", "Blue"]</source>
|helpers
|helpers
|notes
|notes
Line 25: Line 25:
|also_articles
|also_articles
|cat1=Examples
|cat1=Examples
|cat2
|cat2=User-Defined Functions
|cat3
|cat3
|cat4
|cat4
}}
}}

Latest revision as of 15:19, 22 January 2015

Summary

Function: list ListItemDelete( list mylist, string element );

Returns a list that is a copy of mylist but with the first instance of element removed.

• list mylist list to remove items from
• string element item to remove from mylist

See also: Lists

Specification

list ListItemDelete(list mylist,string element_old) {
    integer placeinlist = llListFindList(mylist, [element_old]);
    if (placeinlist != -1)
        return llDeleteSubList(mylist, placeinlist, placeinlist);
    return mylist;
}

Examples

list mylist = ["Red", "Green", "Blue", "Brown"];
list myShortenedList = ListItemDelete(mylist, "Brown");
//myShortenedList is now ["Red", "Green", "Blue"]