Grasshopper

algorithmic modeling for Rhino

Hi everyone, im trying to write a code which increases the value of an integer by one if the input becomes 0 but i couldnt manage take this data it always remain as 0 (the integer which is suppose to be increased) when the input becomes zero the integer outputs a sudden value (1) but then it is zero again here is the code that i wrote inside c# script,

private void RunScript(int x, int y, ref object A)
{

if (x == 0)
{
y++;
}


A = y;

Print(x.ToString());
Print(y.ToString());
Print(A.ToString());


}

Views: 2025

Replies to This Discussion

Hello,

if you want to add 1 every-time your x int goes to zero then this should work

private void RunScript(int x, ref object A)
{

{
if (x == 0)
{
y++;

}

A = y;
Print(x.ToString());
Print(y.ToString());
}
}

// <Custom additional code>
private int y = 0;
// </Custom additional code>

}

or if you don't want to keep on the counting

private void RunScript(int x, ref object A)
{

int y = 0;

{
if (x == 0)
{
y++;

}

A = y;
Print(x.ToString());
Print(y.ToString());
}
}

this will do.

M.

thnaks a lot it partially works now but now it suddenly increases the value too much at one time (i mean it suppose to be 1 when it is increased from 0 but it goes like 112)

the new code i wrote is this;

for(int i = 0; i < z; i++)
{
if(x == y )
{ b = b + 1;

}


A = b;
Print(x.ToString());
Print(b.ToString());
Print(A.ToString());
}

like I said. the first case "stores" the number of times an equality appears, and adds +1 every time. So if you moved the slider to 0, 112 times you should be getting the right result.

The second code resets the value to zero every time the slider changes. So the result only goes from 0 to 1.

my input is not a slider it is a modulus with a counter input so the input of my c# code counts to a domain and resets but when it counts the code cathes the '0' input more than one times.

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2025   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service