- Home /
Can I get a warning if I (involuntarily) declare a new js variable in an assignment?
If I mistype a variable in an assignment a new variable is created. That is a vary nasty situation, as it is hard to find.
Can I make Unity accept only variables when declared with a leading var? If not, can I get warnings?
Thanks, Flo
Answer by Eric5h5 · Feb 15, 2010 at 11:36 AM
No...Unity used to provide warnings about unused variables in JS in a past version, but doesn't anymore for some reason. (At least not for local variables.) Hopefully they will put this feature back sometime.
@Eric5h5 Do you think this could be "fixed" by using some manual patch file, or something more automated?
It's up to Unity Technologies to fix it, by doing whatever it is they were doing with their Javascript compiler in Unity 2.1 (I believe that's the last version that had proper warnings about unused variables in Javascript).
I wouldn't be so bold about that, Eric. Did you know about this following link? Look at AngryAnt's script: http://answers.unity3d.com/questions/1657/best-strategies-for-not-accidently-editing-whilst-still-running/1668#1668
I'm not sure how that's relevant. An editor script for copying component values doesn't help with script compiling at all.
Truth be told, I haven't read it. But I've tested it, and if it can interfere with the interface I've imagined of pre-compiler.
Answer by JDonavan 1 · Feb 16, 2010 at 12:06 AM
If your script is written in C# you will receive a compiler error when you make a mistake like that. So if you find yourself making this mistake often you might consider switching to C#.
Gotta love language fanatics that vote down a valid answer.
It's not a valid answer; the question is specifically about Javascript. It's true that C# doesn't have this problem, but that's not relevant here--Javascript used to not have this problem too. For language debates, use the Unity forums.
Not interested in a language debate. Simply offering a valid alternative to solve his problem since it can't be solved in javascript.
@JDonavan I think the problem is the way you said it. But I agree it's a valid answer - the OP doesn't seem to be aware that C# doesn't have this issue.