Particle System c#

Hello, I am learning c# for particle system and I am following a tutorial from the website below - Particle System | ShaunWu
I did exactly as suggested on the website but I am getting error at the end and the script doesn’t run. Can someone have a look at it and let me know that what is going wrong! Thanks in advance. :slight_smile:

Particle (16.6 KB)

You must not declare tempVelocities and tempPositions in a method. They must be on the class

And now there is a index problem !!

Thanks so much @laurent_delrieu, I tried your solution and as you said there is index error, and I have no idea what that is cuz I have just started learning c# for rhino. How can I solve it?

You’ll have to find the bug. Here it is not clear where it is. I use archaic methods in Grasshopper
The System.Windows.Forms.MessageBox.Show("bla bla ");
you put that in the code and if it is shown the error is before.

A more simple way is to write in a log file on the desktop. I use a lot

 public static void LogPrint(string msg)
            string text = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\logErrorParticles.txt";
            using (var sw = System.IO.File.AppendText(@text))

In visual studio it a bit more easy as you can put stop points …

it is not really a bug you didn’t put the good conditions.
First you use a polyline. You have to use line. If anchors are on the lines, the lines will not move.
I did that and it works. 3 anchors points and 6 lines.

Can you please post the geometry , I couldnt get it!

Here there is something but the system could be not stable, mass damping … It is simulation, time step and algorithm must be well chosen. It must be Euler resulotion, Runge Kutta is better …

Particle (18.9 KB)

Thank you so much @laurent_delrieu , I just wanted to ask you how can I achieve something in c# as below posted images.