Reset list values every given time

reset
unhandled
list

(Pablo Ant Mo) #1

Hi!
I’ll try to be quick and clear. I have the Firefly “Frequency Spectrum” tool outputting real-time noise data in multiple frequencies. I want to store the first 50 values of the first 30 frequencies in a tree which would represent the different noises that sounded over a period of time.
It would be something like a recorder that stops recording once it reaches 50 values for the 30 branches. I’ve tried to code it in C# (I have zero knowledge about coding) using the recorder for getting the data but I’m just able to make the same as the Prune command does.
Can anyone help me?
Thanks!

private void RunScript(DataTree<double> listsbox, int readingMax, ref object A)
{
  if (listsbox.DataCount > readingMax)
  {
    // erase the list}
    listsbox.ClearData();
  }
  A = listsbox;
}

(David Rutten) #2
  private void RunScript(double Data, int Limit, ref object A)
  {
    _data.Add(Data);

    if (_data.Count > Limit)
      _data.RemoveRange(0, _data.Count - Limit);

    A = _data;
  }

  // <Custom additional code> 
  private readonly List<double> _data = new List<double>();
  // </Custom additional code> 

Don’t put in negative limits.

record_n_values.gh (19.1 KB)


(Pablo Ant Mo) #3

Thanks a lot for the quick answer, David!
Keep up the great work.