Haiku Walking Arrays

snx

Member
I'm writing a script to check whether certain lights are on (and if so turn them off). I'm trying to loop through an array but keep throwing an error on the "controller.withUnitNumber()" method. Bear in mind I'm completely new to javascript.

This for/next loop works but the units in question are not continuous.

Code:
for(n = 19; n <=31; n++) {
	 var intLight = controller.unitWithNumber(n);
	 if (intLight.isOn == true) {
	 helper.logToExternalFile('Lighting.log', ds + " - " + intLight.bestDescription + " On, Turning it Off");
	 intLight.off()
	 }
}

This code throws an error "controller.withUnitNumber()" requires a single argument of type Number so I'm guessing my array isn't getting initialized or I have some syntax missing/screwed up?

Code:
var iUnits = Array("6","12","13","18","19","20","22","23","24","26","27","28","29","30","31");	
for (var i = 0, l = iUnits.length; i < l ; i++) {
	 var n = iUnits[i];
	 var intLight = controller.unitWithNumber(n);
	 if (intLight.isOn == true) {
	 helper.logToExternalFile('Lighting.log', ds + " - " + unit.bestDescription + " On, Turning it Off");
	 intLight.off()
	 }
}

Thanks and this is a fantastic piece of software by the way.
 
Back
Top