Forums > Javascript

manipulating strings

July 10, 2006 | 5:33 pm

Hello,

I’d like to build a variable message in javascript for the object line
(like 0, 1000 1000), but I don’t manage to delete the space beetween "0"
and ",".
Is there a function like concat(string1, string2, …) in the Max
environnement.
I try something below but it does work.

Thanks a lot
Patrick

max v2;
#N vpatcher 10 59 656 730;
#P window setfont "Sans Serif" 9.;
#P number 355 278 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 270 118 27 196617 – 0;
#P message 398 179 74 196617 0 , 1000 1000;
#P newex 258 234 32 196617 print;
#P message 270 141 63 196617 longueur $1;
#P number 210 68 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 210 99 59 196617 arrivee $1;
#P number 155 68 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 155 99 54 196617 depart $1;
#P newex 312 231 40 196617 line 0;
#P newex 312 189 47 196617 r mess1;
#P newex 155 187 74 196617 js com_line.js;
#P connect 4 0 3 0;
#P connect 3 0 0 0;
#P connect 5 0 0 0;
#P connect 7 0 0 0;
#P connect 6 0 5 0;
#P connect 1 0 8 0;
#P fasten 6 0 10 0 215 92 275 92;
#P connect 10 0 7 0;
#P fasten 4 0 10 1 160 89 292 89;
#P connect 1 0 2 0;
#P connect 9 0 2 0;
#P connect 2 0 11 0;
#P pop;

————the name of the js file is com_line.js—————–
inlets = 3;
outlets=1;

var debut =0;
var fin =10;
var dure=10;

function depart(v)
{
debut = v;
messnamed("mess1", debut,",",fin, dure);
}

function arrivee(v)
{
fin = v;
messnamed("mess1", debut,",",fin, dure);
}

function longueur(v)
{
dure = v;
}

function reset()
{
debut = d;
fin = 10;
dure=10;
post("reset done");
}


July 10, 2006 | 6:54 pm

use + to concactenate, for example

var string1="pre";
outlet(0,string1+"fix");

will ouput "prefix"

p

On Jul 10, 2006, at 10:33 AM, patrick wrote:

> Hello,
>
> I’d like to build a variable message in javascript for the object line
> (like 0, 1000 1000), but I don’t manage to delete the space beetween
> "0" and ",".
> Is there a function like concat(string1, string2, …) in the Max
> environnement.
> I try something below but it does work.
>
> Thanks a lot
> Patrick
>
> max v2;
> #N vpatcher 10 59 656 730;
> #P window setfont "Sans Serif" 9.;
> #P number 355 278 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P window linecount 1;
> #P newex 270 118 27 196617 – 0;
> #P message 398 179 74 196617 0 , 1000 1000;
> #P newex 258 234 32 196617 print;
> #P message 270 141 63 196617 longueur $1;
> #P number 210 68 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P message 210 99 59 196617 arrivee $1;
> #P number 155 68 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P message 155 99 54 196617 depart $1;
> #P newex 312 231 40 196617 line 0;
> #P newex 312 189 47 196617 r mess1;
> #P newex 155 187 74 196617 js com_line.js;
> #P connect 4 0 3 0;
> #P connect 3 0 0 0;
> #P connect 5 0 0 0;
> #P connect 7 0 0 0;
> #P connect 6 0 5 0;
> #P connect 1 0 8 0;
> #P fasten 6 0 10 0 215 92 275 92;
> #P connect 10 0 7 0;
> #P fasten 4 0 10 1 160 89 292 89;
> #P connect 1 0 2 0;
> #P connect 9 0 2 0;
> #P connect 2 0 11 0;
> #P pop;
>
> ————the name of the js file is com_line.js—————–
> inlets = 3;
> outlets=1;
>
> var debut =0;
> var fin =10;
> var dure=10;
>
>
> function depart(v)
> {
> debut = v;
> messnamed("mess1", debut,",",fin, dure);
> }
>
> function arrivee(v)
> {
> fin = v;
> messnamed("mess1", debut,",",fin, dure);
> }
>
> function longueur(v)
> {
> dure = v;
> }
>
> function reset()
> {
> debut = d;
> fin = 10;
> dure=10;
> post("reset done");
> }
>


July 10, 2006 | 7:42 pm


July 10, 2006 | 7:49 pm


July 10, 2006 | 7:58 pm

On Jul 10, 2006, at 12:42 PM, patrick wrote:

> But it still not works for line. It tells : line doesn’t undestand
> the message "0,"
> The curious thing is :
> – if I print the message named it is 0, 2000 2000
> – if I prepend it to a message box it write 0, 2000 2000
> it seems that the message is not a real list of numbers but text.
> Any idea?

Commas are not part of messages (nor strings), they are delimiters
between multiple messages to specify sequence. The way I’d approach
this from JS would not consist of making a string containing a comma,
but rather send a sequence of messages–i.e. for (0, 2000 2000) use
the following:

outlet(0,0);
outlet(0,2000,2000);

I’m not sure that any means of setting a message box text to contain
a comma delimited message sequence from JS is available unless you
use scripting to instantiate the corresponding message box. To my
knowledge, there’s currently no way to set the message *text* which
is parsed into an *atom list* as is what happens when editing the
text buffer of a message box from the UI.

However, there might be some way to accomplish this that I’m
overlooking (fromsymbol or something). Personally, I’ve never had the
need to do this, so someone else might be able to offer additional
insight if they’ve found a way to communicate an "A_COMMA" atom to
the message box’s prepend set message. Traditionally, there has been
no support for sending A_COMMA or A_SEMI atoms through max patch cords.

-Joshua


July 11, 2006 | 12:40 am

Quote: jkc wrote on Tue, 11 July 2006 07:58
—————————————————-
> so someone else might be able to offer additional
> insight if they’ve found a way to communicate an "A_COMMA"
> atom to the message box’s prepend set message. Traditionally,
> there has been no support for sending A_COMMA or A_SEMI atoms
> through max patch cords.

So you’re saying a simple backslash (as below) shouldn’t work? I’ve been using it for quite a while now ;-)

Or do you mean there’s no way to send the backslashed comma or backslashed semicolon as part of a message from within a js? I’ve not found a way to do that.

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P comment 452 69 73 196617 ditto from js;
#P newex 533 135 29 196617 t set;
#P newex 423 203 59 196617 prepend set;
#P newex 423 178 50 196617 zl group;
#P newex 441 149 74 196617 append \,;
#P button 423 68 15 0;
#P window linecount 0;
#P message 423 333 127 196617;
#P window linecount 1;
#P newex 441 119 50 196617 js;
#P message 637 95 50 196617 quit;
#P window linecount 0;
#P message 637 177 126 196617;
#P window linecount 1;
#P newex 637 145 63 196617 prepend set;
#P newex 637 118 115 196617 prepend \; max;
#P button 205 68 15 0;
#P newex 205 375 34 196617 print;
#P user hslider 51 107 18 128 128 1 0 0;
#P newex 320 164 50 196617 t set;
#P message 231 139 50 196617 1 , 2 , 3 , 4;
#P window linecount 0;
#P message 205 338 120 196617;
#P window linecount 1;
#P newex 205 233 59 196617 prepend set;
#P newex 205 208 50 196617 zl group;
#P newex 231 164 74 196617 append \$1 \,;
#P comment 51 69 128 196617 bang , then move the slider;
#P comment 636 70 149 196617 semicolon seems to work too;
#P connect 18 0 19 0;
#P connect 15 0 18 0;
#P connect 17 0 19 0;
#P connect 17 0 15 0;
#P connect 17 0 21 0;
#P connect 10 0 3 0;
#P connect 10 0 6 0;
#P connect 10 0 7 0;
#P connect 21 0 16 0;
#P connect 20 0 16 0;
#P connect 19 0 20 0;
#P connect 12 0 13 0;
#P connect 11 0 12 0;
#P connect 14 0 11 0;
#P connect 6 0 2 0;
#P connect 5 0 9 0;
#P connect 8 0 5 0;
#P connect 7 0 5 0;
#P connect 2 0 3 0;
#P connect 3 0 4 0;
#P connect 4 0 5 0;
#P window clipboard copycount 23;

The js:

function bang()
{
outlet(0, 1);
outlet(0, 2);
outlet(0, 3);
outlet(0, 4);
}


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