algorithmic modeling for Rhino
Hello everyone
I have a noobinsh question about recursion in GH - C# component
If I declare a list inside the C# component of say values like int or Point3d or whatever How can I update the contents of that list recursively on each refresh of the definition (with a timer or manually with F5) and avoid clearing the list by re-declaring it anew with
List<int> myList = new List<int>(); ??
I have a bool toggle and two if branches inside the component the first for clearing the list (reset) and the second for doing some operations on the list like doubling the values on every refresh.
I would like to resolve this internally inside the component (so no hoopsnake) if possible without needing to write data to the disk
I attached the .gh file with a simple def illustrating my question. There are no errors but once the list is initialized on the first branch the values inside are cleared and list voided when the component is refreshed for use of the data inside the second if branch.
I want to use this approach to be able to control and visualize the updated solution in the viewport (of course using actual geometry not ints :))
Any help would be appreciated.
Thanks
Tags:
you can define a static field. And attach a timer to the script... so it will count und reset when bool false
define a field in //<Custom additional code> ....
public static int counter = -1;
and in your runscript to this....
private void RunScript(bool start, List<object> x, ref object A)
{
if(counter != -1)
{
A = counter;
counter++;
}
if(start == false){counter = -1;}
if(start == true && counter == -1){counter = 0;}
}
hope this helps
Hey Andrei-
I've just started getting into timers myself...the key is to declare the variables you'd like to keep persistent outside of the scope of the sub, in the additional code area. Then also you don't need to call any additional loops...the timer simply re-executes the script.
Thank you all.
It worked.
Just had to move the <list> declaration outside the sub.
Many thanks
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by