Hi guys,
I am wondering how to initialize n amount of class objects in an array and keep persistent data. I think that I have the logic correctly in setting up my array, initializing all my class objects in a for loop, looping through them and calling all their methods (see below). The problem is, that in every solution of the component, the data from the previous run is lost and the locations of the walkers are not updating properly. Attached is a simplified version of one of my random walker codes.
Any suggestions will be great.
Thank you
private void RunScript(bool run, int number, ref object A)
{
List<Point3d> walkerList = new List<Point3d>();
if(run)
{
rw = new RandomWalk[number];
for (int i = 0; i < rw.Length; i++)
{
rw[i] = new RandomWalk(Util.GetRandomPoint(0, 20, 0, 20, 0, 0), number);
rw[i].Move();
walkerList.Add(rw[i].Move());
}
Component.ExpireSolution(true);
}
else
{
Print("test");
}
A = walkerList;
}
// <Custom additional code>
public RandomWalk[] rw;
public class RandomWalk
Zuardin Akbar
If I understand you correctly, maybe you should create the list in the additional code (static mode) , so it's not gonna be refreshed every iteration?
List<Point3d> walkerList = new List<Point3d>();
Sep 5, 2017