why the first Item is not the expected after replace items?
It should be seven
L = [A,B,C,D]
I = [X,Y,Z]
i = [2,0,1]
Just read the description of the parameters.
You’re saying, in list L replace item with index 7 with value “cero”.
Yes, and why the result is thirteen instead zero
ps. sorry for the misspelling… it’s zero not cero
In index 7 put “cero” -> ok.
In index 14 put “one” -> ok.
In index 15 put “six” -> ok.
In index 0 put “seven” -> wrong.
In index 1 put “fourteen” -> ok.
In index 6 put “fifteen” -> ok.
Ohhh I see the bug,
since integers numbers can not be null they are converted to 0, and even if you have specified another value for the index 0 before, the last entry remains, then it happens:
In index null (0) set “thirteen” when reading the elements with index 13.
@DavidRutten keep an eye on this.
oh! It’s much more complex than I tought
Hmm, this is true of
int, but not of
GH_Integer which is how integer data is stored in Grasshopper. GH_Integer is a class and can definitely be null. But you’re probably right in that the Replace component doesn’t even look at the
GH_Integer data and automatically converts the whole list into
ints thinking nobody would provide null indices.
To be clear, what exactly is supposed to happen if you provide a null index? Nothing? I can make that happen, but perhaps it makes more sense to not allow such behaviour to begin with?
Logged under RH-45592.
I think that throwing an error would be appropriate, since is no longer a correct operation and dealing with it with automatic behavior can lead to confusion.
Now I understand why it’s not working. And as @Dani_Abalde said, It can lead to confusion.
So… maybe I´m not in the right way to solve my definition with this component. If my list items provide the item index to replace with, but I always have some nulls what can I do?
Remove nulls with Clean Tree component.
If you need to remove those items in one list that are null, and remove associated items from another list, you need to use a combination of Null Item and Cull Pattern.