Problem with replace item

unhandled

(Gethze) #1

why the first Item is not the expected after replace items? :face_with_raised_eyebrow:
It should be seven


#2

L = [A,B,C,D]
I = [X,Y,Z]
i = [2,0,1]
=> [Y,Z,X,D]

Just read the description of the parameters.
You’re saying, in list L replace item with index 7 with value “cero”.


(Gethze) #3

Yes, and why the result is thirteen instead zero

ps. sorry for the misspelling… it’s zero not cero


#4

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.

Hmmm…


#5

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.


(Gethze) #6

oh! It’s much more complex than I tought :face_with_monocle:


(David Rutten) #7

Hmm, this is true of System.Int32 or 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.


#8

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.


(Gethze) #9

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?


#10

Remove nulls with Clean Tree component.


(David Rutten) #11

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.


(Gethze) #12

Thanks to @Dani_Abalde and @DavidRutten! :smile: