Over the past few months I've noticed weird things happen when you try to use certain expressions or functions inside of array index brackets.
For instance, I realized that you cannot use MyArray.Find(var) inside of MyArray's index brackets (and added a note to the wiki). This will compile fine but it will result in really weird things happening at runtime:
MyArray[MyArray.find(targetValue)] = newValue
Today I also noticed something far more bizarre. If you do something like this (I did it in a loop, but here's what it would look like written out):
i = 0MyArray[i * 5] = 32MyArray[i * 5 + 1] = 33MyArray[i * 5 + 2] = 34MyArray[i * 5 + 3] = 35MyArray[i * 5 + 4] = 36i = 1MyArray[i * 5] = 37MyArray[i * 5 + 1] = 38MyArray[i * 5 + 2] = 39MyArray[i * 5 + 3] = 40MyArray[i * 5 + 4] = 41i = 2MyArray[i * 5] = 42MyArray[i * 5 + 1] = 43MyArray[i * 5 + 2] = 44MyArray[i * 5 + 3] = 45MyArray[i * 5 + 4] = 46
You will end up with an array that looks like this:
MyArray[0] = 32MyArray[1] = 0MyArray[2] = 0MyArray[3] = 0MyArray[4] = 0MyArray[5] = 37MyArray[6] = 5MyArray[7] = 5MyArray[8] = 5MyArray[9] = 5MyArray[10] = 42MyArray[11] = 10MyArray[12] = 10MyArray[13] = 10MyArray[14] = 10
In other words, it seems that papyrus evaluates the index correctly, and then for some reason ignores the expression after the equals sign and instead assigns the first part of the expression inside the index brackets to the array value. Weeeeiiiirrrd
I tested it a bit more and it seems to work whenever there is only one operator sign inside the brackets (like MyArray[i + 1] or MyArray[i * 4]) but if you add more than that, things start getting a bit trippy. I think I've gotten to the point now that I'm just going to be afraid to stick anything besides a single number or variable inside array index brackets.
Food for thought...