Forums > Javascript

What's wrong with this loop?

November 20, 2013 | 11:31 am

I’m a js newb modifying a script that’s specifically for drum racks in Live, but am getting some errors. It seems to break at the iterate function at the end.

autowatch = 1;
outlets = 1;

function msg_int(num)
{
	var api = new LiveAPI('id ' + num);
	if (!api) return;

	iterateChains(api);
}

function iterateChains(api)
{
	
		var count = api.getcount('chains'); // only racks have chains
		chainApiPath = dequotePath(api);
		for (i = 0; i < count; i++) {
			chainApi = new LiveAPI(chainApiPath + ' chains ' + i);
			var chainName = chainApi.get('name');
			//outlet(0, chainName);

			if (chainApi) {
				var dCount = chainApi.getcount('devices');
				var deviceApiPath = dequotePath(chainApi);
				for (var j = 0; j < dCount; j++) {
					var deviceApi = new LiveAPI(deviceApiPath + ' devices ' + j);
					if (deviceApi) {
						var devClass = deviceApi.get('class_display_name');
						var devName = deviceApi.get('name');
						var devId = deviceApi.id;
						var cCount;
						var chainsApi;
						var k;
						
						if (deviceApi.get('can_have_chains') == 1) {
							cCount = deviceApi.getcount('chains'); // only racks have chains
							chainsApiPath = dequotePath(deviceApi);
							for (k = 0; k < cCount; k++) {
								chainsApi = new LiveAPI(chainsApiPath + ' chains ' + k);
								var chainsName = chainsApi.get('name');
	/*-------------------->*/				iterateChains(chainsApi);
								//outlet(0, chainsName + ' ' + devName + ' ' + devClass);
								outlet(0, chainsApiPath);
								}
						}
               			}
			}
		}
	}
}
iterateChains.local = 1;

function dequotePath(api)
{
	return api.path.replace(/\"/g, ""); // remove quotes
}
dequotePath.local = 1;

November 20, 2013 | 11:36 am

Sorry, trying to get the formatting to work right.


November 20, 2013 | 11:46 am

Hi ! its hard to read .

use

..your code..

then it will be pretty nice looking

anyway . what kind of errors do you have ? that would be helpful .
another things . check every ‘getcount’ if returns apropriate data ,and verify every part separately first to make sure your requests are fine !


November 20, 2013 | 11:48 am
for (j = 0; h < chainsCount; h++) {

 chainsApi = new LiveAPI(deviceApiPath + " return_chains " + h);
 var chainsName = chainsApi.get('name');
//iterateDevices(chainsApi);
 outlet(0, 'return_chains ' + chainsName);

 }

your iteration pointer is wrong

edit :
you updated it . ok , what kind of errors ?


November 20, 2013 | 12:00 pm

Hi, thanks, I edited that part out since it was commented out awhile ago. If I can get the main iteration fine, then when I update that part it should be fine.

Ok, the errors are:
"getcount: invalid property name"
"get: no valid object set"
"invalid path component: ‘chains’"

The amount of errors and their order seem correct in that they’re detecting what they should be detecting, and the path name’s should be correct (ie all the "dequote…")s but it still seems it can’t get past "live_set tracks 0 devices 1 chains 0 devices x"…..where it should get to another iteration of "chains x devices x"

and that’s where I’m stuck…

Thanks for your help.


November 20, 2013 | 12:01 pm

yes, I’ve checked through smaller segments and the only problem is the end "iterateChains(chainsApi)" call.
That’s what breaks it.
I can comment it out and it works fine but then it won’t iterate.


November 20, 2013 | 12:09 pm

js attached


November 20, 2013 | 3:05 pm

It could be something really simple/stupid and it wouldn’t surprise me but I’m stuck.

I implore your assistance!


Viewing 8 posts - 1 through 8 (of 8 total)