Possible bug with If Statements losing nesting

I have a script that needs to behave differently depending whether a single element or multiple elements are being run on (because of transposition logic). But designscript is keeping the nesting regardless of of the if(?) statement. Maybe I’m missing something? Could someone explain if I’m overlooking something.

Try using a dictionary to circumvent the issue.

1 Like

The inline conditional statement takes parameters of type: (bool ? var : var). So if it is passed arguments that are lists, it replicates. For e.g. “true ? [1, 2] : [3, 4]” returns “[1, 2]” and “false ? [1, 2] : [3, 4]” returns “[3, 4]” as expected.

However if there are arguments that are lists of different rank, due to the concept of array promotion in replication, the lower ranked argument gets promoted to a higher ranked one. For e.g. “true ? [1, 2] : [[3], [4]]” returns “[[1], [2]]” since the argument of rank 1, namely [1, 2], gets promoted to argument of rank 2 to match with the other argument. Also “false ? [1, 2] : [[3], [4]]” returns “[[3], [4]]” as expected.

In order to get what you’re expecting you’ll need to prevent replication by enclosing the above statements in an imperative block, such as:
[Imperative]
{
return true ? [1, 2] : [[1], [2]]; // still returns [1, 2] (no replication and no array-promotion)
}
image

2 Likes