coming from a text-based (c#) programming background sometimes grasshopper is quite hard for me to understand. Sometimes i feel so stupid:
in c#, the behaviour i want:
if (x>1)
{
A = 1 / (x - 1); // statemtent 1 true
}
else
{
A = 0.5; // statement 2 false
}
it is obvious, that if the condition is false, the statment 1 is not evaluated.
for x = 1, i will not get a “division by zero” error.
but in grasshopper inside a expresion component if((x>1),(1/(x-1)),0.5)
will throw an exception “division by zero” for x=1
why ?
why is the statement in the “true” section evaluated - even if the condition is false?
what do i miss ?
thanks @emerson.porras for having a look at this and for your suggestion
… does not work either… the brackets have no effect.
i found a really ugly, unsatisfying way not get an error:
combine an expresion (output text) with evaluate (to do the logic)…
(but it feels like bricolage):
Here’s another nasty little workaround that exploits the idea that it’s ok to corrupt the algorithm so it can evaluate safely, given that the altered evaluation won’t be output: