JavaScript to Max/Jitter string parsing issue
Sorry for the double post. I didn't notice that there was a JS forum until after I posted this in the Max forum.
=============================
I'm porting a Flash application over to Max/Jitter. I've rebuilt most of the logic in Max, but I have one routine that runs a lot of trig in a for loop that seems to run significantly faster using JavaScript than the uzi object. Basically, it plots points in a wave and sends OpenGL commands to an outlet.
With the LCD object, I could spit out hundreds of messages per frame without a hitch. But now I'm using OpenGL in Jitter and have found that it doesn't respond well to a ton of messages, but it has no performance issues receiving single messages with hundreds of commands.
That said, I'm building the command string no problem, but when Max receives it, there are quotes around the whole thing. If I remove the quotes with the RegExp object (regexp (") @substitute %0), all the commas are replaced with backslash comma.
Any tips on getting this command over to jit.gl.sketch? Is this something I should be trying in JS or Max?
Here's my JavaScript:
function bang() {
// Start the command string
var strCommand = "reset, glcolor 1 1 1 1, glbegin line_strip, "
// Decimate the frequency to make the wave prettier
numPitch *= numFactor;
// Loops through width
for (var i = 0; i < numWaveLength; i++) {
// Adjust ramp to add curve
numAmp -= numRamp;
// Adjust Y
numYPosition = numAmp * Math.sin(((i / numWaveLength) * (Math.PI * numPitch)) + numPhase);
// Draw line where amp is over 0
if (numAmp > 0) strCommand += "glvertex " + String(i / numWaveLength) + " " + String((numYPosition + numYOffset) / (numYOffset * 2)) + ", ";
}
outlet(0, strCommand + "glend");
}
Not that this helps you in any way, but I am having the same issue.
If I do this:
messageString = "read" + k + ".aiff";
read[k].set("string",messageString);
I don't get quotes in my message box (useless though because it outputs garbage). But as soon as I do this (note the space after read):
messageString = "read " + k + ".aiff";
It puts quotes around the whole thing.
Bizarre behavior.
messageString = "read" + " " + k + ".aiff";
doesn't work either.
Thanks if you can help us both out.
If you use the +concatenation+ symbol you will create one string. if you want to send the message as a list you need to format it with ,commas, instead.
outlet(0,"try","this","instead");
lh
Excellent. Thank you. I figured this out in the wee hours of the morning purely by accident.
I still can't figure out how much of javascript Max understands. It seems hit or miss.