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.
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.
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.
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.