Set difference not working with integers :D

To make set operations even more confusing, set difference is not working with integers for some reason.

Why? @DavidRutten

200601 set difference (17.4 KB)

1 Like

Sets components have generic type parameters, they can work for numbers, integers, strings… so to work with them properly, you must to make sure both inputs are the same type, so convert your text to integers (data from panels are text).

1 Like

Don’t use Panels to feed in data. That’s strings.

Doing strings vs integers is not going to work.

Whenever you work with numerical data always ensure you use exactly that, numerical data. You need to pipe all panels through their own Integer parameter to ensure it is all numbers.

1 Like

ok, I understand but in some situations strings do behave as numbers, but not for stets

Because it is not always clear when data gets converted and when not you should use panels really only for displaying, unless you explicitly convert (like with the Integer parameter).

In sets components, the values are irrelevant, what matters is his unique identifier, known as a hash. If you have the value 42 in integer, in decimal, and in text, being different type, they have a different identifier, even though for us it is the same number.

1 Like

Or to say it in a different way

42 != "42" != 'forty two' != 42.0



That’s interesting. And how do I see this hash?

You could write some custom component, but I wouldn’t bother. Instead don’t rely on automatic conversion to always happen.

As said, the set components can work with other data than just numbers, including strings.

Whenever possible ensure your data is of the type it should be. Since Panel component always does conversions you are not guaranteed the type to stay the same or correct. Therefor the advice to not pipe data through Panel into another component. Not in the middle of a definition taking data from one component, giving it to the next. Especially then only use to show, not forward, data.

1 Like

From programming persective it is the type of the data that matters: integer, double, string, mesh, etc.

Just add this line to the C# scripting component:

A = x.GetHashCode();

But maybe for some type in GH has his own hash method.

1 Like


Read the entire reply, and you’ll find the answer.


Here an extreme example of conversion going bad:

1 Like