Javascript Script Size Limit?

Hello,

Apologies if this is covered somewhere already. I was unable to come up with a successful combination of search keys to look it up if it is.

Anyway, is there a size limit to a javascript script? I have moderately large script (around 1160 lines) that is having compilation problems, or more accurately Unity is no longer sniffing out the problems it should. The last few changes I’ve made to my script have had syntax errors (mostly misnamed boolean variables) that Unity has just been passing over and compiling anyway.

For instance I would have something like

victimRescued = true;

However I don’t actually have a variable defined as victimRescued, the definition is for this:

private var victimSaved : boolean = false;

However Unity just passed over the “victimRescued” and compiled it. As expected, the code wasn’t working because “victimSaved” was never getting set to true. So okay, maybe I was using “victimRescued” somewhere else . . . I then did a search through the code for “victimRescued” to find where it was defined and what I was using it for. The search turned up no results, which I found odd. So I then changed the line of code to:

victimsdjkshdfkajshd = true;

The above still compiled with no errors. Since then I’ve noticed problems with three or four other lines that seem to be invisible to the syntax checker.

[Update] - So this phenomenon is not limited to the script I was talking about above, it seems to be happening to other scripts as well (one I was just looking at was only 200 lines long). It seems to mostly ignore incorrect variable names, though not always. Semi-colons, parentheses, braces, etc. all seem to come up with errors when misplaced or missing, but incorrect variable names don’t trigger “unknown identifier” errors like they should . . . though sometimes they still do.

Is this a known issue? If so, what causes it? If it’s not a known issue, does anyone have any ideas what it could be?

Thanks,
~Rob

I have a project with a 2979 line script and a 2635 line script, and didn’t have any problems. (Normally my scripts aren’t anywhere near that big, but in those cases, breaking them up would only have resulted in things being more complicated.)

I think what you’re seeing is that you don’t need to explicitly write “var” to define variables. This is valid code:

private var someVar = true;

function Start () {
   someVarr = false;
}

That may look like a typo, but what you’re actually doing is defining a local variable in Start called “someVarr”. Unfortunately, the “unused variable” warning in javascript went away in 2.1, which is very useful for allowing you to catch mistakes just like this. I logged a bug a long time ago, but alas, it’s still open.

–Eric

I wish #pragma strict disallowed this behavior alongside dynamic typing.

Interesting . . . I was about to say how it was inconsistent, but I just realized why it would seem that way . . . I think some of the booleans were being used in if() statements before any sort of local definition-creating-assignments and thus were triggering errors.

This is the first project I’ve done in Unity 2.x and now that you mention it, I haven’t seen an “unused local variable” warning in a long time. ; )

Thanks, Eric, though the lack of warning is mildly irritating, at least I know that things aren’t starting to fall apart at the seams when I’m about 75% complete with this thing, haha.