- Home /
JavaScript issue: apparently invisible variables
Hello. Below, the first index of "uvs" which is assigned a value is uvs[7] and the value is Vector2(1.0, 1.0). The Debug.Log below confirms this. However so does not the corresponding value of uvs displayed in the editor, which displays (0.1666667, 0.33333333). At the same time the visual consequence of the code supports the "wrong" editor value and not the value displayed by the Log. Am i doing something wrong?
(The missing declarations for vv, uphi and dtl are done at the start of the original script as float, float and integer respectively. None of the present values are used anywhere else in the script and Ugen() is called from Start(). This is the only custom script in the scene, assigned to an empty object.)
function UGen(){ uvs = new Vector2[Verts.length]; vv = 1.0; uphi = 1.0; dtl = 6;
for (var zz=0; zz < dtl - 3; zz++){
vv = 1.0 - ((1.0 / (dtl -3))*zz);
for (var k=0; k < dtl; k++){ uvs[k+dtl+1] = Vector2(uphi, vv); Debug.Log(uvs[k+dtl+1]); uphi = 1.0 - ((1.0 / dtl) * k); } }
}
Answer by loramaru · May 06, 2011 at 02:32 AM
The index you are assigning to, k+dtl+1, in uvs does not use zz in its computation. Therefore every time through your outer loop, you will assign to the same set of indexes. So the (1.0, 1.0) Vector2 that you see in the log is the first value assigned to index 7, from the pass where zz = 0 and k = 0. The (0.1666667, 0.33333333) Vector2 you see in the inspector is the final value assigned to index 7, from the pass where zz = 2 and k = 0.
Thanks, i was thinking too much about the effect i was trying to produce and not enough about the code itself. This also exposes my faulty debug method.