Difference between revisions of "ListItemDelete"

From Second Life Wiki
Jump to: navigation, search
m
Line 1: Line 1:
{{LSL Header}} __NOTOC__
+
{{LSL_Function
<div id="box">
+
|func=ListItemDelete
== Function: [[list]] ListItemDelete([[list]] {{LSL Param|mylist}}, [[string]] {{LSL Param|element}}); ==
+
|mode=user
<div style="padding: 0.5em;">
+
|p1_type=list|p1_name=mylist|p1_desc=list to remove items from
Removes one item from a list.
+
|p2_type=list|p2_name=element|p2_desc=item to remove from '''mylist'''
 
+
|return_type=list
 +
|return_text=that is a copy of '''mylist''' but with the first instance of '''element''' removed.
 +
|func_footnote=
 
See also: [[List|Lists]]
 
See also: [[List|Lists]]
 
+
|spec=<lsl>list ListItemDelete(list mylist,string element_old) {
<lsl>
+
list ListItemDelete(list mylist,string element_old) {
+
    list newlist;
+
 
     integer placeinlist = llListFindList(mylist, [element_old]);
 
     integer placeinlist = llListFindList(mylist, [element_old]);
     if (placeinlist != -1) {
+
     if (placeinlist != -1)
         newlist = llDeleteSubList(mylist, placeinlist, placeinlist);
+
         return llDeleteSubList(mylist, placeinlist, placeinlist);
    }
+
     return mylist;
     return newlist;
+
}</lsl>
}
+
|caveats
 
+
|examples=<lsl>
</lsl>
+
list mylist = ["Red", "Green", "Blue", "Brown"];
 
+
list myShortenedList = ListItemDelete(mylist, ["Brown"]);
list myShortenedList = ListItemDelete(mylist,"Brown");
+
//myShortenedList is now ["Red", "Green", "Blue"]</lsl>
 
+
|helpers
 
+
|notes
</div>
+
|also
 
+
|also_functions
{{LSLC|Examples|ListItemDelete}}
+
|also_articles
 +
|cat1=Examples
 +
|cat2
 +
|cat3
 +
|cat4
 +
}}

Revision as of 03:28, 5 August 2008

Summary

Function: list ListItemDelete( list mylist, list 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
• list element item to remove from mylist

See also: Lists

Specification

<lsl>list ListItemDelete(list mylist,string element_old) {

   integer placeinlist = llListFindList(mylist, [element_old]);
   if (placeinlist != -1)
       return llDeleteSubList(mylist, placeinlist, placeinlist);
   return mylist;

}</lsl>

Examples

<lsl> list mylist = ["Red", "Green", "Blue", "Brown"]; list myShortenedList = ListItemDelete(mylist, ["Brown"]);

//myShortenedList is now ["Red", "Green", "Blue"]</lsl>