Difference between revisions of "ListStridedRemove"

From Second Life Wiki
Jump to navigation Jump to search
m (Added details..)
m (<lsl> tag to <source>)
 
(5 intermediate revisions by 2 users not shown)
Line 7: Line 7:
|p4_type=integer|p4_name=stride
|p4_type=integer|p4_name=stride
|return_type=list
|return_type=list
|return_text=that contains the elements of '''myList''' but with the strides in the range of '''start''' to '''end''' removed.
|return_text=
|func_desc=Removes a specified part of a strided list.
|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=
|func_footnote= created fixed and improved by Madpeter Zond
<lsl>
<source lang="lsl2">
// to remove indexs from a list (normaly one thats been strided use this function
<lsl>list ListStridedRemove(list src, integer start, integer end, integer stride) {
    return llDeleteSubList(src, start * stride, (stride * (end + 1)) - 1);
}</lsl>
// to remove every stride from a list use this function
list ListStridedRemove(list src, integer start, integer end, integer stride)
list ListStridedRemove(list src, integer start, integer end, integer stride)
{
{
    // fixed and improved by Madpeter Zond (the wiki entry is trash please update it)
     if((start < 1) || (stride < 1)) return src; // reverse stride not supported
     if((start < 1) || (stride < 1)) return src; // reverse stride not supported
     else
     else
Line 36: Line 30:
     }
     }
}
}
</lsl>
</source>


See also: [[List#Strided_lists|Strided Lists]]
See also: [[List#Strided_lists|Strided Lists]]
|examples=
|examples=
<lsl>list customers = ListStridedRemove(customers, 0, 0, STRIDELENGTH);</lsl>
<source lang="lsl2">list customers = ListStridedRemove(customers, 0, 0, STRIDELENGTH);</source>
|spec
|spec
|helpers
|helpers
Line 49: Line 43:
|notes
|notes
|cat1=Examples
|cat1=Examples
|cat2
|cat2=User-Defined Functions
|cat3
|cat3
|cat4
|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);