Delete Index Entries after Condition Check

Update:
Problem Couldnt be fixed, cause couldnt found (I still guess its the problem mentioned in the title). Big thanks to @Keith_1357 and @Silver-Streak for the help.

So I found out if a condition checks anything in regards of a scene array index number, it creates this index if none exists.

Thats a huge problem using arrays where the indexes are building up on each other, because then I have an extra index in the middle of the array list with no value. Im using the array to manage object instances positions for dynamic UI elements; if

It would be better if after the condition created an extra index, to delete the index automatically.

As explained in your other thread, this is how all variable conditions and actions work, as the engine and renderer do not allow for null values.

It is very unlikely this will be changed due to the above, but what may be likely is implementing a condition similar to the “child exists” condition for structure variable, but for index entries of an array. Then you could simply add it as a condition to your event so it doesn’t fire if the index doesn’t exist to begin with.

That said, in the interim you can use the ‘Number of children’ condition to accomplish something similar to this, since arrays don’t allow you to skip indexes. If you are checking for index numbered 4, simply add the condition “number of children of array >= 5” (since indexes start at 0, index 4 would be the 5th index).

If index 4 doesn’t exist, the event will never fire.

1 Like

Hi, yes im using the “number of children” condition but sometimes it’s not possible since there are points where I don’t know how many children are in the array.

Im not saying it shouldn’t create an index by checking the condition, but it should remove the entry automatically after it’s checked.

Can you add more context? Maybe a screenshot of your events. There might be a different strategy.

If you want to check if there’s an index 5 then you could check if the child count is > 4 (since indexes start at 0, it would have 0-3) This part gives me a headache. Sometimes, I wish arrays would start at zero.

Or do you want to know if say index 6 has a value meaning not null in cases where say index 7 is set to a value to an array that had indexes 0 to 5. Since, it would add indexes 6 and 7 leaving 6 as null.

If you’re working on something that might skip indexes then a structure might be easier.

Now I have a good example where the Indexes don’t behave how they should be.

in the picture, the number “9999” should be set to index 9 but strangely its set to index 0.
This is a huge problem, there is no way for me to get the right index right now.


The Index from the ArrayTools “IndexOf” is 8, that’s why +1 should be index9. Index9 at that point already exists. -1 is correctly index7 as seen in the picture, also -0 is index8 correctly.
It seems like every action after the -0 action does not activate, if I put -0 at last then the actions trigger correctly but cause further bugs on following actions about the same array.

here’s another variation:
Index 6 (-2) and Index 7 (-1) were not executed.


I’d recommend making sure it isn’t an extension or expression issue first.

If you manually type in index 8+0, 8-1, 8+1, etc, does it behave as expected in that use case?

1 Like

What are the values of the other variables?
Is IndexSort an array?

I would look at the value of the other variables.

Also, when you do a search it might need a failsafe in case the value isn’t found. If the value doesn’t exist it looks like the function IndexOf is going to return - 1

Is the value always going to exist? I would check the IndexOf separately and check if it’s being found.

You need to breakdown all of the values and make sure they’re what you’re expecting them to be.

Hi, yes if I to
Var[0][7] = 99
Var[0][8] = 999
Var[0][9] = 9999

You are right, the IndexOf returns -1. But The index must exist, there are always at least 9 Indices if this event triggers. My guess is, similar to the Title, the program creates an extra index with the value 0, maybe at index 9 why the IndexOf returns -1.

The expressions work correctly, if I change the order of the action inside the single event, the solution is correct but somehow creates further bugs on events below which 100% shouldn’t be since I tried other more complex workarounds where the arrays are the exact same without further bugs.

If it’s returning -1 then it’s not finding the value. It uses -1 because indexes must be positive. Since indexes can’t be negative it must be changing it to zero instead of causing it to crash.

I tested it and nothing seems to get created if you try to create an index of -1 and reading index - 1 seems to return 0 instead of the value of index 0.

It all depends on which part is causing a possible error or crash.

Your events are using the search to get a value in another array. So, while the IndexOf returns - 1 getting the value of index -1 is returning 0 not the value in index 0. At least that’s what seems to happen in my testing.

You need to find out why it’s returning -1 and if. It’s possible the exact value doesn’t exist then you would need 2 events. One that does something if the value is found and one to do something else if the value isn’t found.

The expression has to find the value, everything seems correct. When I switch the actions inside the single event, the expression finds the value. Every action inside the event does not interfere with each other.

The expression just finds the value on index 8 and makes +1. That works if I put this expression on first or second order.

Look all 3 actions are exactly the same except the -1 and +1 at the end to get the next lower/higher index.


But if I change the order, it shows it correctly, but this way it causes crashes even tho other ways giving this exact array cause no further crashes.


I don’t think ill find a solution, im using the longer method, thanks to everyone :clap:

It’s tough to tell but if it’s searching the array and replacing values. Is it possible that alone each line is good but one line is changing a value and it’s making another search fail.

To be clear. This part is getting the value in the index at kkk and then adding and subtracting the value. If you’re trying to get the previous and next value within the other array then the plus and minus needs to be withing the right brackets.

Example

Abc[x+1] gets value of index [x+1] 
Abc[x] +1 gets the value of index [x] adds 1

It can be difficult to count brackets and parenthesis.
Ok, if that’s not the issue then IDK.

1 Like

Ive checked it still did not work but thank you very very much for your time Keith. :clap:

1 Like