Can't seem to output strings through a for loop
So this is probably just yet another case of me missing something glaringly obvious, but I can't seem to get the JS object to output anything when I try to send out a text string. I've been trying on and off to see what I'm getting wrong for quite a while now but I think I'm stumped. Anyone have any idea where I'm going wrong in this? Thanks.
inlets= 1;
outlets= 1;
var padNum= [
81, 82, 83, 84, 85, 86, 87, 88,
71, 72, 73, 74, 75, 76, 77, 78,
61, 62, 63, 64, 65, 66, 67, 68,
51, 52, 53, 54, 55, 56, 57, 58,
41, 42, 43, 44, 45, 46, 47, 48,
31, 32, 33, 34, 35, 36, 37, 38,
21, 22, 23, 24, 25, 26, 27, 28,
11, 12, 13, 14, 15, 16, 17, 18];
var prevLength = 0;
function stepLight(length){
function stepUp(){
for (var i= prevLength; i > length; i++){
outlet(0,"144"+" "+padNum[i]+" "+"37");
}
}
function stepDown(){
for (var i= prevLength; i < length; i--){
outlet(0,"144"+" "+padNum[i]+" "+"0");
}
}
if(length > prevLength){
stepUp();
};
if(length < prevLength) {
stepDown();
};
prevLength = length;
};
There's nothing wrong with the construction of your output messages, but...
You have the functions stepUp() and stepDown() inside the stepLight() function. How do you expect that those functions will be called by the Max patch?
I actually didn't have that at first. I did it after I was already stumped and just taking a few shots in the dark at how my syntax might be wrong (probably a dumb idea, I know). Either way the intention was for the function to be called if the conditional was met. Originally the function looked more like this, which also didn't output anything:
function stepLight(length){
if(length > prevLength){
for (var i= prevLength; i > length; i++){
outlet(0,"144"+" "+padNum[i]+" "+"0");
}
};
if(length < prevLength) {
for (var i= prevLength; i < length; i--){
outlet(0,"144"+" "+padNum[i]+" "+"37");
}
};
prevLength = length;
};
The > and < signs should be interchanged. Both for loops never meet a true condition. The first one should read: as long as i is smaller than length, increase i.
Alternatively you could use outlet(0, 144, padNum[i], 0);
which does not return a symbol but a list.
....of course it was that. My hubris had me convinced there's no way I could screw up a for loop I guess. Well, in the future hopefully someone else with a similar situation will find this thread, and not have to embarrass themselves quite as much. Thanks for your patience.