algorithmic modeling for Rhino


I have a problem that code in picture_a is work fine,but when i added one line code("public static int i=0".),itwon't work anymore(picture_b)!

What did i miss?



Code in picture_b does not work because i add "public static int i=0".

Views: 762


Reply to This

Replies to This Discussion

Isn't the autogenerated Script_Instance class a singleton? Every time you edit the code it creates a new different type with a single instance.

Nope, once code is compiled, any subsequent requests to compile the same code within the same instance of Rhino will return the same assembly. Any change, no matter how trivial or meaningless, will cause a recompile, but if you instantiate the same C# component umpteen times it'll only compile once.

You do of course get different instances of your script class, so class level variables won't be shared across them, but type level (i.e. static) once will be.

I see, I just managed to make a static field change in a scripting component and watch it update in a copy of it.

I can understand why I've never seen this happen before. If the field is reassigned every time a script instance is run you wouldn't notice any difference from a local variable.

Yes indeed, unless the static is supposed to retain information between solutions it's fine, albeit still risky and not very future proof.

You even bothered to refactor it with dependency injection :P

But underscores (even in fields) doesn't follow C# naming conventions.

No feeling about the redundant access modifiers...

Yeah it's also my one major break from the MS conventions. All (non-const) class level fields are prefixed by an underscore. I find it just really helps me keep track of what's what.


I have written a MOUSE_EVENTS class which has successfully solved the problem(MouseCallback Failed),but the code is running so laggy!

What caused this problem?

gh file!







  • Add Photos
  • View All

© 2019   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service