x


UnityScript variable scope

Obviously every method in UnityScript has a separate scope for variables, but blocks don't:

var y;
if (true) {
    var y; // error: There is already a local variable with the name 'y'.
    var x;
} else {
    var x; // error: There is already a local variable with the name 'x'.
}

From what i found on the wiki, an older version of UnityScript had the usual approach of blocks providing a new declaration space. Thus i'm wondering, is this intentional for some reason or just an oversight?

more ▼

asked Oct 21 '11 at 08:00 PM

gfr gravatar image

gfr
451 1 3 4

I would expect the first error. The second one surprises me and is good to know about...

Oct 21 '11 at 08:12 PM jahroy
(comments are locked)
10|3000 characters needed characters left

1 answer: sort newest

No, it's always worked that way. It's intentional, because that's how Javascript works.

more ▼

answered Oct 21 '11 at 08:20 PM

Eric5h5 gravatar image

Eric5h5
80.3k 42 132 521

(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:

x289
x40

asked: Oct 21 '11 at 08:00 PM

Seen: 943 times

Last Updated: Apr 22 '12 at 05:23 AM