[sharingisfun] make a js array patch

Feb 2, 2006 at 3:25pm

[sharingisfun] make a js array patch

typing out an array like:
var arrayname = new Array() ;
arrayname[1] = “one” ;
arrayname[2] = “two” ;

is boring as the array gets larger. so here is a max patch that generates the array, given a comma-delimited message of arrayname and elements. Just cut and paste from the text window into your js.

#P window setfont Geneva 9.;
#P window linecount 1;
#P comment 451 94 147 196617 go ahead punk , make my array;
#P comment 464 74 90 196617 set starting index;
#P message 427 49 295 196617 arrayname , one , two , three , four , left-top , rt-top , left-bot , rt-bot;
#P number 427 72 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P button 427 91 20 0;
#N vpatcher 10 59 296 428;
#P window setfont Geneva 9.;
#P newex 75 291 53 196617 append \;;
#P newex 102 269 146 196617 sprintf var %s = new Array();
#P newex 60 170 36 196617 zl reg;
#P newex 50 36 88 196617 t open b b 2 clear;
#P newex 91 97 29 196617 t l 1;
#P newex 143 103 27 196617 0;
#P newex 89 75 47 196617 gate 2 2;
#P newex 144 186 51 196617 tosymbol;
#N counter;
#X flags 0 0;
#P newobj 112 158 66 196617 counter;
#P newex 89 129 40 196617 t b b l;
#P newex 50 270 33 196617 t cr l;
#P newex 60 218 119 196617 sprintf %s[%ld] = “%s”;
#P newex 50 314 40 196617 text;
#P inlet 160 83 15 0;
#P inlet 50 16 15 0;
#P inlet 126 55 15 0;
#P outlet 69 72 15 0;
#P connect 2 0 13 0;
#P connect 15 0 6 0;
#P connect 5 0 6 0;
#P connect 16 0 4 0;
#P connect 6 0 4 0;
#P connect 13 4 4 0;
#P connect 13 0 4 0;
#P connect 7 0 14 0;
#P connect 14 0 5 0;
#P connect 13 1 0 0;
#P connect 6 1 16 0;
#P connect 12 0 14 1;
#P connect 13 3 10 0;
#P connect 12 1 10 0;
#P connect 10 0 7 0;
#P connect 10 1 12 0;
#P connect 12 0 15 0;
#P connect 7 1 8 0;
#P connect 8 0 5 1;
#P connect 1 0 10 1;
#P connect 11 0 8 2;
#P connect 13 2 11 0;
#P connect 7 2 9 0;
#P connect 3 0 11 1;
#P connect 9 0 5 2;
#P pop;
#P newobj 427 125 76 196617 p makejsarray;
#P comment 427 33 217 196617 create comma-delim names of array elements:;
#P hidden connect 1 0 4 0;
#P hidden connect 2 0 1 0;
#P hidden connect 4 0 1 1;
#P hidden connect 3 0 1 2;
#P window clipboard copycount 7;

#24235
Feb 8, 2006 at 12:25am

Hi
I tried to create new panel objects using javascript:
var a = this.patcher.newobject(“panel”,100,100,12,12);
From this I get: error: patcher: doesn’t understand “panel”.

It works when I do it with a toggle: var a =
this.patcher.newobject(“toggle”,100,100, 15, 0);
So I checked by stepping trough the patchers objects using the apply
method. I get for the Maxobj property maxclass for some of my
objects the word “panel”.
In Max text mode I get for a panel: #P user panel 180 167 12 12;
When I try to script to a thispatcher object with the message “script
new mypanel panel 100 100 12 12″ I get the same error message.

Is it impossible to create panel objects dynamically?
Stefan

#69794

You must be logged in to reply to this topic.