x


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);
  }
  }

}
more ▼

asked May 06 '11 at 02:04 AM

Hiondeux gravatar image

Hiondeux
3 1 1 4

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered May 06 '11 at 02:32 AM

loramaru gravatar image

loramaru
404 1 6

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.

May 06 '11 at 03:50 AM Hiondeux
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3570
x1728
x563

asked: May 06 '11 at 02:04 AM

Seen: 531 times

Last Updated: May 06 '11 at 02:04 AM