Array goes crazy. If I add smth 1 time, it adds 2 positions, If I add 2 things it contains 4 positions and has 3times the same index? Pls send the exorcist

Hi there!

So I simply go through a sequence to check for something. If true, add my data structure to my data structure array. (on begin/default the array is empty)
I now debugged it since I had some issues and it weirds me out.
If its true the first time (add mydatastructure one time to the array) the array contains 2 items. Whereas the first one looks like null.
And even weirder, if its true a second time it has 4 items and 3 times index 1?

I be honest, i havent debugged a lot of arrays yet… but im pretty sure thats not how its suppose to look.
Why does it add 2 items each time?
Why (and how is this even possible) have I 3x the same index (1)?

Here a picture of the content. Top: structure was added 1 time. Bot: structure was added 2 times.

Here is the whole thing:

Appreciate your help!

Your logic looks really clunky. Why don’t you split the logic into manageable chunks? From what i can see here, its going too add two elements cause the branch at the end will be true twice. You can use AddUnique, but this might mask a potential future problem.

aah it does not add two items when its only true once… the content is just too long to display so it gets split into several rows. That makes much more sense now.

I dont find it clunky at all tbh, is this really considered clunky in the outer world?
And the branch gladly can be true several times, that wasnt my problem.

i like to split things into manageable chunks, like your adding to array could be a function that takes in the integer, and verifies it, etc. I find that the best pattern for clean, easy to read code.

manageable… much interpretation possible here :smiley:
but your profile tells me I might shall listen to your voice. So I will take your advice and keep things in smaller tasks. Might even help to re-use the code in more places :thinking:

Yes, you should never have duplicate code, if you find yourself writing duplicate code, you should make that a function or put it in a blueprint library.