Forums > MaxMSP

JScript adds double quotes to output

August 10, 2006 | 6:54 pm

Hello!

First post in forum, well, cool community!

To my question:

I’m using JScript to utilize some tasks within a patch. I have this line for an output:

outlet(0,p1 + x1 + ‘ ‘ + x2);

p1, x1 and x2 are all strings. And the output has " " these double quotes at the beginning and end of the output, the object that I want to use does not understand messages with quotes.

I’m making this to bypass some "prepend set" and "message box" objects. Any way to get rid of the double quotes without much effort? This code will be executed nearly every 5-10ms so there should be an easy way to get around this. I hope.

Thanks for all the help!

Batuhan


August 10, 2006 | 8:05 pm

your output string is treated by max as 1 symbol, because you formatted it
that way. strings with whitespace which are not one symbol is a list in max,
and can be a mix of any type. You can strip the quotes by using
[fromsymbol], but that’s not what you want. You need to output the string as
a list instead of concatenating the various strings into a symbol. like
this:

outlet(0,p1,x1,x2);

I don’t know what you intended to do with the ‘ ‘ but you can’t use a
whitespace in a list like that afaik. If you need p1 and x1 to be one
string:

outlet(0,p1+x1,x2);

hth, -thijs

On 8/10/06, Batuhan wrote:
>
>
> Hello!
>
> First post in forum, well, cool community!
>
> To my question:
>
> I’m using JScript to utilize some tasks within a patch. I have this line
> for an output:
>
> outlet(0,p1 + x1 + ‘ ‘ + x2);
>
> p1, x1 and x2 are all strings. And the output has " " these double quotes
> at the beginning and end of the output, the object that I want to use does
> not understand messages with quotes.
>
> I’m making this to bypass some "prepend set" and "message box" objects.
> Any way to get rid of the double quotes without much effort? This code will
> be executed nearly every 5-10ms so there should be an easy way to get around
> this. I hope.
>
> Thanks for all the help!
>
> Batuhan
>
>


August 10, 2006 | 8:16 pm

I am trying to achieve a list(the ‘ ‘ seperates two values in the list, how lame is that? :) ), and what you say makes perfect sense. I will try and report asap.

Thanks!


August 10, 2006 | 11:14 pm

Ok, the output message was supposed to be a "linesegment" message followed by 4 values as a list, so "fromsymbol" worked fine, translating the qouted text to [linesegment a b c d].

But preparing this as a string in javascript was waaay toooo slow speedwise, so i decided to only get the values out of the script then format them as a list with a pack, then using [prepend linesegment]. It worked 3-4x faster, that proves that I’m really bad at coding I guess.

Ok, thanks for the help! Problem solved.


August 11, 2006 | 11:06 am

On 11 Aug 2006, at 01:14, Batuhan wrote:

> But preparing this as a string in javascript was waaay toooo slow
> speedwise, so i decided to only get the values out of the script
> then format them as a list with a pack, then using [prepend
> linesegment].

JavaScript’s outlet statement will take multiple arguments. There’s
no assembling a space-delimited string only to re-parse it with
fromsymbol; apart from anything else, you’re polluting the Max symbol
table.

– N.

nick rothwell — composition, systems, performance — http://
http://www.cassiel.com


August 11, 2006 | 12:16 pm

On 11 Aug 2006, at 13:06, Nick Rothwell wrote:

> There’s no assembling a space-delimited string

That should read: "There’s no point assembling a space-delimited
string …"

nick rothwell — composition, systems, performance — http://
http://www.cassiel.com


August 11, 2006 | 2:04 pm

Yeah, I get the point. This happened because of my meaningless desire to het rid of the "prepend linesegment" objects after the jscript, so I thought they had to be formatted as a text wirhin the script. and the ‘ ‘ blank quotes were needed for formatting the text, then [from symbol] would translate them. This way brought my CPU to it’s knees(%100 usage). I managed to make the script simple and do the rest of the job with max objects. Now it eats %2 of my CPU.


August 11, 2006 | 2:44 pm

On 11 Aug 2006, at 16:05, Batuhan wrote:

>
> Yeah, I get the point. This happened because of my meaningless
> desire to het rid of the "prepend linesegment" objects after the
> jscript,

Couldn’t you just put the ‘linesegment’ tokens in the JavaScript
instead?

> This way brought my CPU to it’s knees(%100 usage). I managed to
> make the script simple and do the rest of the job with max objects.
> Now it eats %2 of my CPU.

I’m not sure that this fix would have such an effect, unless you’re
really generating masses of symbols in quick succession.

– N.

nick rothwell — composition, systems, performance — http://
http://www.cassiel.com


August 11, 2006 | 3:18 pm

Sorry, I have never used JScript before, so I do not get what you mean by "tokens". And I am pretty new at Max/MSP too, so sorry if I’m asking dumbish questions.

And for the CPU load issue:

The code that runs fine right now is this:

x1 = l1 * Math.sin(phi1);
y1 = l1 * Math.cos(phi1);
x2 = (x1 + l2 * Math.sin(phi2));
y2 = (y1 + l2 * Math.cos(phi2));
outlet(0, x1);
outlet(1, y1);
outlet(2, x2);
outlet(3, y2);

I get these x1 y1 and x2 y2 pairs and process them in another patcher and it works fine. The CPU hogging code was looking something like this(with all the job given to script-I am rewriting but should be ok I hope)

x1 = l1 * Math.sin(phi1);
y1 = l1 * Math.cos(phi1);
x2 = (x1 + l2 * Math.sin(phi2));
y2 = (y1 + l2 * Math.cos(phi2));
te = ‘linesegment ‘
outlet(0, te + 400 + ‘ ‘ + 300 ‘ ‘ + (x1+400) + ‘ ‘ + (y1 + 300));
outlet(1, te + (x1+400) + ‘ ‘ + (y1+300) + ‘ ‘ + (x2+400) + ‘ ‘ + (y2+300));

so those outlets would send:
0:
"linesegment 400 300 somex somey"
1:
"linesegment somex somey anotherx anothery"

with the quotes. When I send these to fromsymbol objects then send that output to an lcd object, my CPU goes 100%. 400 and 300 are offset values for x-y positions by the way. Instead if I use the simplified code and use another patcher to do that job for me(with modifiable offset values), It works fine and uses 2-5% of my CPU(Athlon XP2000+).

Oh and this code sends values every 5ms or so and this is only the output section.


August 11, 2006 | 3:41 pm


August 11, 2006 | 3:46 pm

On 11 Aug 2006, at 17:18, Batuhan wrote:

> te = ‘linesegment ‘
> outlet(0, te + 400 + ‘ ‘ + 300 ‘ ‘ + (x1+400) + ‘ ‘ + (y1 +
> 300));
> outlet(1, te + (x1+400) + ‘ ‘ + (y1+300) + ‘ ‘ + (x2+400) +
> ‘ ‘ + (y2+300));

It depends on how often you’re making these calls, but yes, you
should be doing something like

outlet(0, ‘linesegment’, x1, y1, x2, y2);

otherwise you’re generating lots of intermediate symbols (containing
JavaScript’s rather verbose floating-point printing). Also, I suspect
that each "+" generates an intermediate string, unless it’s being
somewhat smart in optimisation.

– N.

nick rothwell — composition, systems, performance — http://
http://www.cassiel.com


August 11, 2006 | 4:04 pm

Ok, I managed to do it outside Jscript, and using those linesegments as sprites now(using another patcher to handle these tasks and sprite drawing messages became inevitable). But I now know what I did wrong, so thanks a bunch!


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