// SPDX-License-Identifier: MIT // Copyright (c) 2026 Incoprea // Reject spikes with a rolling median // Not compiled or tested in-world // Setup: Put in a spare prim you own. Touch through a sample sequence containing one large outlier. // Stop / restore: Disable or remove the script. It only reports to its owner and does not change prim properties. Reset clears its temporary state. // Notes: All sample values are floats so LSL sorting treats them as one type. The filter delays fast genuine changes as well as rejecting isolated spikes. // License: see LICENSE in this distribution. // Original Incoprea example. MIT. Owner-only calculation; no scene changes. list INPUT=[10.0,11.0,10.0,80.0,12.0,11.0,10.0]; list window; integer cursor; default { touch_start(integer detectedCount) { if (llDetectedKey(0) != llGetOwner()) return; float value=llList2Float(INPUT,cursor); cursor=(cursor+1)%llGetListLength(INPUT); window += [value]; if (llGetListLength(window)>5) window=llList2List(window,-5,-1); list sorted=llListSort(window,1,TRUE); integer n=llGetListLength(sorted); float median=llList2Float(sorted,n/2); if (!(n%2)) median=(median+llList2Float(sorted,n/2-1))*0.5; llOwnerSay("Input="+(string)value+"; median="+(string)median+"; window="+llDumpList2String(window,",")); } changed(integer change) { if (change & CHANGED_OWNER) llResetScript(); } }