Attempted to access index 50 from array with length 50!


What does this mean? Surely that would work?

Er, nope. A 50 element array goes from 0 to 49 :wink:

I understand that, but since it’s still trying to access the 50 item (49) it should be able to?
image

The for loop also starts at index 0 and is trying to access the same index from the WallTiles array (i assume its trying to access index 0)

The “For Loop” node is special. Both First Index and Last Index are inclusive. So you can’t just feed it the length of the array.

So how would i go about fixing this? I understand the concept of inclusive now that you mentioned it although im not sure how to fix it

So i found the solution with trial and error. Turns out i need to subtract 1 from the index to make it 0-49 instead of 0-50!

Be careful if the array can be empty as well though, in that case you’d get 0 to -1 as the indices. Is there any specific reason you can’t use For Each Loop to iterate directly over the elements of the array?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.