Difference between revisions of "ListStridedRemove"

From Second Life Wiki
Jump to: navigation, search
(New page: {{LSL Header}} __NOTOC__ <div id="box"> == Function: list ListStridedRemove(list {{LSL Param|src}}, integer {{LSL Param|start}}, integer {{LSL Param|end}}, integer {{L...)
 
m (<lsl> tag to <source>)
 
(9 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{LSL Header}} __NOTOC__
+
{{LSL_Function
<div id="box">
+
|mode=user
== Function: [[list]] ListStridedRemove([[list]] {{LSL Param|src}},  
+
|func=ListStridedRemove
[[integer]] {{LSL Param|start}}, [[integer]] {{LSL Param|end}}, [[integer]] {{LSL Param|stride}} ) ;
+
|p1_type=list|p1_name=src
==
+
|p2_type=integer|p2_name=start
<div style="padding: 0.5em;">
+
|p3_type=integer|p3_name=end
Removes a specified part of a strided list.
+
|p4_type=integer|p4_name=stride
 +
|return_type=list
 +
|return_text=
 +
|func_desc=Removes each stride from a list, example a list of 1,2,3,A,1,2,3,A after ListStridedRemove(list,4,0,4); would be 1,2,3,1,2,3
 +
|func_footnote= created fixed and improved by Madpeter Zond
 +
<source lang="lsl2">
 +
list ListStridedRemove(list src, integer start, integer end, integer stride)
 +
{
 +
    if((start < 1) || (stride < 1)) return src; // reverse stride not supported
 +
    else
 +
    {
 +
        integer loop = start - 1;
 +
        integer tricker = 0;
 +
        integer maxlen = llGetListLength(src);
 +
        if((end == 0) || (end > maxlen)) end = maxlen;
 +
        while(loop < end)
 +
        {
 +
              integer pointid = loop-tricker;
 +
              src = llDeleteSubList(src,pointid,pointid);
 +
              tricker++;
 +
              loop+=stride;   
 +
        }
 +
        return src;
 +
    }
 +
}
 +
</source>
  
 
See also: [[List#Strided_lists|Strided Lists]]
 
See also: [[List#Strided_lists|Strided Lists]]
 
+
|examples=
<lsl>
+
<source lang="lsl2">list customers = ListStridedRemove(customers, 0, 0, STRIDELENGTH);</source>
list ListStridedRemove(list src, integer start, integer end, integer stride) {
+
|spec
    return llDeleteSubList(src, start * stride, (end * stride) + stride - 1);
+
|helpers
}
+
|also_functions
+
|also_events
list customers = ListStridedRemove(customers, 0, 0, STRIDELENGTH);
+
|also_tests
</lsl>
+
|also_articles
 
+
|notes
 
+
|cat1=Examples
</div>
+
|cat2=User-Defined Functions
 
+
|cat3
{{LSLC|Examples|ListStridedRemove}}
+
|cat4
 +
}}

Latest revision as of 14:21, 22 January 2015

Summary

Function: list ListStridedRemove( list src, integer start, integer end, integer stride );

Removes each stride from a list, example a list of 1,2,3,A,1,2,3,A after ListStridedRemove(list,4,0,4); would be 1,2,3,1,2,3
Returns a list

• list src
• integer start
• integer end
• integer stride

created fixed and improved by Madpeter Zond

list ListStridedRemove(list src, integer start, integer end, integer stride)
{
    if((start < 1) || (stride < 1)) return src; // reverse stride not supported
    else
    {
         integer loop = start - 1;
         integer tricker = 0;
         integer maxlen = llGetListLength(src);
         if((end == 0) || (end > maxlen)) end = maxlen;
         while(loop < end)
         {
              integer pointid = loop-tricker;
              src = llDeleteSubList(src,pointid,pointid);
              tricker++;
              loop+=stride;    
         }
         return src;
    }
}

See also: Strided Lists

Examples

list customers = ListStridedRemove(customers, 0, 0, STRIDELENGTH);