ListFindListReverse

From Second Life Wiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

User-Defined Function: integer uListFindListReverse( list vLstSrc, list vLstTst );

Returns an integer index of the last instance of vLstTst in vLstSrc

  • vLstSrc: source list to check
  • vLstTst: list to look for

if vLstTst is not found in vLstSrc -1 is returned.
the index of the first element in vLstSrc is 0

Code:

  • LSO: 168 Bytes
  • MONO: 512 Bytes
integer uListFindListReverse( list vLstSrc, list vLstTst ){
    integer vIntRtn;
    if (vLstTst != []){
        integer vIntPst = (vLstSrc != []);
        while ((vIntRtn -= ~llListFindList( llList2List( vLstSrc, vIntRtn, vIntPst), vLstTst )) ^ vIntRtn );
    }
    return ~-vIntRtn;
}
/*//--                       Anti-License Text                         --//*/
/*//     Contributed Freely to the Public Domain without limitation.     //*/
/*//   2009 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ]   //*/
/*//  Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ]  //*/
/*//--                                                                 --//*/

Notes

  • function loops n+1 times (where n = number of instances of vLstTst in vLstSrc).
    • this may make it slow for large lists containing many copies of vLstTst
  • Unlike llListFindList, this function properly returns -1 if either vLstSrc or vLstTst is an empty list([]).