listCompare
Revision as of 05:55, 22 April 2014 by Omei Qunhua (talk | contribs) (Combine LSO and Mono versions. The attempt at the "Voodoo trick" was actually wasting space in the LSO version.)
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
Summary
Function: integer ListCompare( list a, list b );
Efficiently compares two lists for equality (same contents in the same order).
Returns an integer TRUE if the lists are equal, FALSE if not.
• list | a | – | The first list to compare. | |
• list | b | – | The second list to compare. |
Examples
<lsl>integer r = ListCompare([1, 2.0, "3"], [1, 2.0, "3"]); // Returns TRUE integer s = ListCompare([1, 2.0, 3], [1, 2.0, "3"]); // Returns FALSE
integer t = ListCompare([], [1, 2.0, "3"]); // Returns FALSE</lsl>Implementation for LSO or MONO
<lsl> integer ListCompare(list a, list b) {
if (a != b) return FALSE; // Note: This is comparing list lengths only
// The next line is only needed if compiling with LSO if (a == []) return TRUE; // both lists are empty (as both lists are the same length)
return !llListFindList(a, b); // As both lists are the same length, llListFindList() can only return 0 or -1 // Which we return as TRUE or FALSE respectively
} </lsl>