Hello guys!
I am trying to learn some basics on C# so I am pretty amateur.
I try to make a very simple code of a grid. When I make it normal everything works fine but when I try to use additional code and functions something happens with “multiplier” input. I think that I have to initialize it somehow or what? I would appreciate your help!
Thanks in advance!
Grid.gh (5.3 KB)
It can be initialized or not.
But the mistake you made is this:
int _multiplier () ;
which must be
int _multiplier;
usually ()
means a function declaration, which is not used with variables.
Thank you Petras for your answer!
I know that my question maybe is silly but even if I right it like this:
int _multiplier;
what does this error means afterward?
It is not an error, it is just a warning.
It tells you that this variable is not assigned, just like pList.
You can assign a value from runscript if needed.
But I already have an integer slider with values from 0 to 10 which works fine when I don’t use additional code. Why is that?
Thanks again!
You have to pass local variable from runscript to global parameter - _multiplier, then your function will recognize it:
private void RunScript(Point3d p0, int u, int v, int multiplier, ref object A)
{
pList = new List <Point3d> ();
createGrid(p0, u, v);
A = pList;
_multiplier = multiplier;//////////////////// here
}
// <Custom additional code>
List <Point3d> pList;
int _multiplier ;
void createGrid (Point3d p0, int _u, int _v){
for(int i = 0; i < _u; i++){
for(int j = 0; j < _v; j++){
Point3d p = p0 + new Vector3d(i * _multiplier, j * _multiplier, 0);
pList.Add(p);
}
}
}
Ohh…I see now…thank you very much Petras!
Much appreciated!!