manipulating strings


    Jul 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;
    ------------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");
    }

    • Jul 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");
      > }
      >
    • Jul 10 2006 | 7:42 pm
    • Jul 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
    • Jul 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.
      The js:
      function bang()
      {
      outlet(0, 1);
      outlet(0, 2);
      outlet(0, 3);
      outlet(0, 4);
      }