Array breaking when pushing floats into it via a for loop.

so I’m trying to figure out a chunk of code that is supposed to grab a group of objects by tag, and then create a an array of material colors to re-assign to their respective materials as a pulsing animation. the code was designed this way so any object tagged “pulse” would be capable of pulsing without any other changes made to it.

I get a clean count of 95 when I run the code, so I know it’s finding the objects and adding them to the first array. it’s when it tries to add the material colors to the second array when it breaks. I cannot find any examples of this error code online for js.

IndexOutOfRangeException: index
System.Array.System.Collections.IList.get_Item (Int32 index) (at /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System/Array.cs:303)
Boo.Lang.Runtime.RuntimeServices.GetArraySlice (System.Object target, System.Object[] args)
Boo.Lang.Runtime.RuntimeServices.GetSlice (System.Object target, System.String name, System.Object[] args)
Boo.Lang.Runtime.DynamicDispatching.SliceDispatcherFactory+<CreateGetter>c__AnonStorey12.<>m__5 (System.Object o, System.Object[] arguments)
Boo.Lang.Runtime.RuntimeServices.GetSlice (System.Object target, System.String name, System.Object[] args)
Pulse.Awake () (at Assets/Scripts/Pulse.js:57)

the code seemingly causing the bug is below:

private var objects : Array ;
private var objColor : Array ;
private var matNum : int = 1 ; // for development: materials[matNum] ... most will use 1, simple objects will use 0

private var LightsCentral : LightsoutCentral ;

function Awake() 
{
	stageDurations = Array ( pulseTurnOnDuration, pulseStayOnDuration, pulseTurnOffDuration, pulseStayOffDuration ) ;
	objects = GameObject.FindGameObjectsWithTag ("Pulse") ;
	print(objects.length);
	objColor = new Array() ;
	if ( objects.length > 0 ) 
	{
		for ( var i = 0 ; i < objects.length ; i++ ) 
		{
			objColor.Push (objects*.renderer.materials[matNum].color.a) ;*
  •  	}*
    
  • }*
  • print(objColor);*
  • LightsCentral = GameObject.Find ( “ScriptStorage” ) . GetComponent ( “LightsoutCentral” ) ;*
    }
    any help identifying what needs fixed would be greatly appreciated!
    JK

This is your problem…

for ( var i = 0 ; i < objects.length ; i++ ) 

Array indices go from 0 to array length -1, so this should be

 for ( var i = 0 ; i < objects.length-1 ; i++ )

so far, no dice with any of these… I tried switching the array to a list (for the list, used float, realized my mistake, switched to vector4, didn’t work either, settled on color and it worked, kind of)

the error went from that long debug error to a short one saying I was miscasting, and once I got it casting properly… back to the same big error again.

thanks anyhow everybody. at times like this I wish I was a programmer, not a designer.