it's difficult for me to decipher all that, but I'll give you some general info, arrays in construct are 1 based instead of 0 based, so the first index is 1, not 0.
also, your formula there is needlessly convoluted and unreadable, the (Sprite.MeshRows+1)*(Sprite.MeshCols+1)-1 make sure to use enough () to be sure about the order of operations even if it's superfluous just for readability. instead of using one loop with weird formulas to get what you need, why not just have nested loops?
for "x" from 0 to meshrows
for "y" from 0 to meshcols
then use loopindex("x"), and loopindex("y)
also, another thing that would make it less confusing would be not using a 3rd dimension to the array, and instead use 3 separate arrays named x, y, and z
other than that, using those alterations, it'll be quicker for you to find the solution than for me to. also, just for general info purposes, if you're sacrificing readability for optimization purposes, construct can have hundreds of objects all being acted upon and thousands of evaluated conditions and actions per frame with no slowdown, so you don't really need to do stuff like that except in extreme cases that most users never reach