Grasshopper

algorithmic modeling for Rhino

Hey GH community I have a doubt regarding the expression editor, I´m using the "f(x)" and i want the function to recognize numbers ONLY between 6 and 10, im using the expression "5<x≤10" but a message below appears and says "Syntax error: Operator ≤ not defined for bool and int", does somebody has a solution to my problem??

Views: 5567

Replies to This Discussion

thanks! very useful!

The reason your original expression fails is because the comparison operators are not handled at the same time.

 

5 < x ≤ 10

 

First it will compare 5 to x and if 5 is smaller the result will be True, otherwise the result will be False. So now we have two possible remaining expressions:

 

True ≤ 10

False ≤ 10

 

True and False cannot be compared to Integers (actually they probably should, False equals 0 and True equals 1, but if won't solve your problem).

 

You are performing two separate comparisons, which you'll need to write as two separate operations, combining them with a Boolean operator, like so:

 

(x >= 6) And (x <= 10)

 

Which results in the following possibilities:

 

x smaller than 6    ->    (False) And (True)

x larger than 10    ->    (True) And (False)

otherwise            ->     (True) And (True)

 

For And to return True, both the left and the right-hand value must be True, thus the first two possibilities both return False.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

:0 oh thanks for explaining that :D

 

 

Thanks for explaining!! I think I understand better now!

Hey how do you set your Single Variable Functions to show what you wrote in the function without going into the expression editor?

This is really helpful.  I just spent an hour trying to do this by making a quadratic function that only goes below 0 at the range of x values I needed (and ended up with the same problem)

You have to set it up Scott - set up the function by going into the expression designer (editor).

Either that or you can simply write the same thing you typed into expression designer to a Panel, and then connect the panel to the "F" input plug of the "function1" component:

(I typed "x*3" in the expression designer of the first "function1" component)

What Chris did is, he renamed the "F" input of the "function1" component to something else. In this case "x>5, x<10, x=10". You can rename it by yourself by right clicking on that "F" input.

But that does not affect the function. He did that to clarify better what did he write into the expression designer.

I hope I did not make a mistake on this?

It seems it is maybe a time for me to stop playing like somebody that knows some basics of GH.

You got it.  Good explanation.

Chris

Okay, thank you.

I have seen that done a lot on this site and thought it may be some setting in grasshopper I didn't know about.  I need to make a presentation based around my grasshopper definition and this seems like the best way of presenting the definition to someone.

Hello I am getting a simular issue where my expression is  recievening a syntax error no matter how I write it. Anyone know of a solution?

Attachments:

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service