Arrays (401266)

Hi,

I’m tryng to initialize an array, but so far no luck.

var Active = new int [10];
function Start()
{
	for(var ix = 0; ix < 10; ix ++ )
	{
	        Active [ix] = 0;
        }
}

That piece of code, gives me an error of “IndexOutOfRangeException : Array index is out of range.”
If i make a Active.Length , it returns me a lenght of 1.
What am i doing wrong ?
thanks,

Bruno

That code should work as written. The only thing that I can think that might affect it, is if you have modified the array by hand in the inspector - since it’s a public var, it’ll show up and be editable in the inspector, which overrides any values assigned to it in your script when you declare it.

hope this helps!

Yeah, it works fine for me to.

You might want to temporarily change Active to a private var and see what happens.

Yup, now works.
Changing it to a private var fixed it :slight_smile:
thanks guys