llListStatistics
float llListStatistics(integer Operation, list ListVariable)Performs a statistical aggregate function, specified by a LIST_STAT_* constant, on ListVariables.
This function allows a script to perform a statistical operation as defined by operation on a list composed of integers and floats.
Parameters
-
Operation(integer) - One of LIST_STAT_* values
-
ListVariable(list) - Variable to analyze.
Demonstrating All Operations
Section titled “Demonstrating All Operations”// Show results for each operation for a sample listdefault{ state_entry() { list LX = [-1, 3.33, 17, "object", -4.5, 0.8675 ];
llSay(0, "G.Mean= " + (string) llListStatistics(LIST_STAT_GEOMETRIC_MEAN, LX) ); // 0.000000 llSay(0, "Max= " + (string) llListStatistics(LIST_STAT_MAX, LX) ); // 17.000000 llSay(0, "Min= " + (string) llListStatistics(LIST_STAT_MIN, LX) ); // -4.500000 llSay(0, "Mean= " + (string) llListStatistics(LIST_STAT_MEAN, LX) ); // 3.139500 llSay(0, "Median= " + (string) llListStatistics(LIST_STAT_MEDIAN, LX) ); // 0.867500 llSay(0, "Count= " + (string) llListStatistics(LIST_STAT_NUM_COUNT, LX) ); // 5.000000 llSay(0, "Range= " + (string) llListStatistics(LIST_STAT_RANGE, LX) ); // 21.500000 llSay(0, "Std.Dev= " + (string) llListStatistics(LIST_STAT_STD_DEV, LX) ); // 8.258468 llSay(0, "Sum= " + (string) llListStatistics(LIST_STAT_SUM, LX) ); // 15.697500 llSay(0, "Sum of squares= " + (string) llListStatistics(LIST_STAT_SUM_SQUARES, LX) ); // 322.091500
}}Note: Non-numeric entries (like the “object” string in this example) are silently ignored by the function. The geometric mean can produce “NaN” (Not A Number) results when the list contains numbers with mixed signs.
Real-World Usage: Region Performance Monitoring
Section titled “Real-World Usage: Region Performance Monitoring”// Demonstrates using llListStatistics() to track region performance metricslist dil_s;list fps_s;integer ticks = 0;
default{ state_entry() { llSetTimerEvent(1.0); }
on_rez (integer parm) { llResetScript(); }
timer() { dil_s = llList2List(dil_s + llGetRegionTimeDilation(), -60, -1); fps_s = llList2List(fps_s + llGetRegionFPS(), -60, -1); if(3 <= ++ticks) { llSetText( "Dilation: min="+(string) llListStatistics(LIST_STAT_MIN, dil_s) + ", mean=" + (string) llListStatistics(LIST_STAT_MEAN, dil_s) + ", max=" + (string) llListStatistics(LIST_STAT_MAX, dil_s) + ", std.dev=" + (string) llListStatistics(LIST_STAT_STD_DEV, dil_s) + "\n" + "FPS: min="+(string) llListStatistics(LIST_STAT_MIN, fps_s) + ", mean=" + (string) llListStatistics(LIST_STAT_MEAN, fps_s) + ", max=" + (string) llListStatistics(LIST_STAT_MAX, fps_s) + ", std.dev=" + (string) llListStatistics(LIST_STAT_STD_DEV, fps_s), <1.0, 1.0, 0.0>, //yellow 1.0); } }
changed(integer change) { if(change & CHANGED_REGION) { llResetScript(); } }}- This function silently ignores any list entries that are not floats or integers
- All numeric values in a mixed-type list are included in the calculation
- You can use
LIST_STAT_NUM_COUNTto determine how many numeric elements are in a mixed list - The geometric mean calculation only works correctly with numbers of the same sign; mixed-sign lists may produce “NaN”
See Also
Section titled “See Also”llGetListEntryType()- Determine the type of a list elementllListStatistics Test()- Test page for this function