Writing text into [comment] using Javascript

the_man361's icon

Hi.. So I'm starting out with javascript and I've managed to get to a certain point and have become stuck.

Part of my patch generates dynamically using javascript.. ive managed to get it working quite nicely, but there's one thing I cannot figure out.

My patch's javascript generates 'n' [umenu]s and places them in the patcher window. I have arranged for a [comment] to be generated directly above the [umenu] which I would like to show the number of the [umenu]...

i.e above the first generated [umenu] will be a [comment] of '1'. above the second, a [comment] of '2' and so on.

I have got the [umenu]s populating using an array, and I was hoping to use the variable of my counter to populate the comment content too.. as below

for(k=0;k
{
theumenus[k] = this.patcher.newdefault(250+(k*100), 300, "umenu"); //make umenus
thecomments[k] = this.patcher.newdefault(250+(k*100), 280, "comment", k+1); //make comments, fill with 'k+1'
}

I would have thought that after the "comment" field, the next field would be it's content, but apparently not as all my generated [comment] boxes are empty.

However, this doesn't put anything in the [comment] text field... how do I dynamically put text into a [comment]?? I've had a search around and have run into the 'message (string, …)' javascript, but I'm unclear how to use it (syntax wise). Supposedly it sends a message to the object it points at.

Any help muchly appreciated :)

Ooh, and, while I'm here... what is the javascript to make an object part of presentation mode?

Luke Hall's icon

You use the variable you've set to refer to the object and call some of the avaiable methods. In this case you'll want to do something like the example below.

lh

thecomments[k] = this.patcher.newdefault(250+(k*100),280,"comment");
thecomments[k].message("set",k+1);
thecomments[k].presentation(1);

the_man361's icon

Thankyou for the quick reply there :)

I get the syntax for the message script now, wasn't sure before. Cheers!