In Unity’s JavaScript, method-level variables are always available throughout the method. (Skip over code if you know exactly what I mean).
For instance:
function SomeFunction(){
for (var i : int = 0; i < foo; i++)
{
//declared var in for(){}
var TMCBSRef : TMCBS = cell.GetComponent(TMCBS);
}
//---------------------------------------------------------------
for (var cell : GameObject in CellsArray)
{
//declared var in foreach(){}, "Already Exists" error
var TMCBSRef : TMCBS = cell.GetComponent(TMCBS);
}
}
I understand this is intended behavior, but I’m wondering if there’s a keyword I can slap on there to make these vars limit their scope to whatever statement they’re in, a la every other programming language I’m familiar with? Otherwise, how do you guys mitigate the confusion caused by this issue?
Thanks for your time.