Forums > Javascript

Setting attributes using newobject()

June 3, 2008 | 6:37 pm

I’m trying to create a bunch of number boxes with a custom appearance,
and I cant’ quite figure out what I’m missing here. All the values
prior to my setting the bordercolor attribute work fine (postion, nin
& max values, etc.) but none of the appearance-related attributes
change. Am I doing something completely boneheaded, or are appearance
attributes handled differently?

M

this.patcher.message("script", "newobject", "flonum",
"@varname", i + "_volbox",
"@patching_rect", 280, 400, 130, 20,
"@maximum", 0.0,
"@minimum" , -90.,
"@bordercolor" , 0.0, 0.0, 0.0, 0.0,
"@textcolor" , 0.031373, 0.160784, 0.466667, 1.0 ,
"@fontface", 1,
"@triangle" , 0,
"@fontsize" , 12.0,
"@bgcolor" , 0.94902, 0.94902, 0.94902, 0.509804 ,
);


June 3, 2008 | 9:36 pm

On 3 juin 08, at 20:37, mattyo wrote:

> I’m trying to create a bunch of number boxes with a custom
> appearance, and I cant’ quite figure out what I’m missing here. All
> the values prior to my setting the bordercolor attribute work fine
> (postion, nin & max values, etc.) but none of the appearance-related
> attributes change. Am I doing something completely boneheaded, or
> are appearance attributes handled differently?
>
> M
>
>
> this.patcher.message("script", "newobject", "flonum",
> "@varname", i + "_volbox",
> "@patching_rect", 280, 400, 130, 20,
> "@maximum", 0.0,
> "@minimum" , -90.,
> "@bordercolor" , 0.0, 0.0, 0.0, 0.0,
> "@textcolor" , 0.031373, 0.160784, 0.466667, 1.0 ,
> "@fontface", 1,
> "@triangle" , 0,
> "@fontsize" , 12.0,
> "@bgcolor" , 0.94902, 0.94902, 0.94902, 0.509804 ,
> );

This is working fine here (after removing the extra coma at the end).
blue text flonum, without triangle, and almost half transparent white
background as expected.

ej


June 3, 2008 | 9:47 pm

I think I had accidentally put the js out of the searchpath, and it
was not recompiling properly — it all seems fine now.

But while I’m on the topic, let me ask this: I’m trying to create a
bunch of messageboxes with a different index in each, so that they
would appear as [set 0 $1] [set 1 $1] etc, using an incrementing index
in the js to get the changing value. However, you can’t format that
using the @text attribute, as the middle value is a variable, and

@text "set", v, "$1"

or any of several variants doesn’t work. I’ve run around it by
creating the object first with the @text attribute set to "set" &
then doing this:

var mess = this.patcher.getnamed( v + "_index");
mess.message("append", v);
mess.message("append", "$1");

but I feel it lacks style. is there a better way?

Thanks,

M

On Jun 3, 2008, at 17:36, Emmanuel Jourdan wrote:

> On 3 juin 08, at 20:37, mattyo wrote:
>
>> I’m trying to create a bunch of number boxes with a custom
>> appearance, and I cant’ quite figure out what I’m missing here.
>> All the values prior to my setting the bordercolor attribute work
>> fine (postion, nin & max values, etc.) but none of the appearance-
>> related attributes change. Am I doing something completely
>> boneheaded, or are appearance attributes handled differently?
>>
>> M
>>
>>
>> this.patcher.message("script", "newobject", "flonum",
>> "@varname", i + "_volbox",
>> "@patching_rect", 280, 400, 130, 20,
>> "@maximum", 0.0,
>> "@minimum" , -90.,
>> "@bordercolor" , 0.0, 0.0, 0.0, 0.0,
>> "@textcolor" , 0.031373, 0.160784, 0.466667, 1.0 ,
>> "@fontface", 1,
>> "@triangle" , 0,
>> "@fontsize" , 12.0,
>> "@bgcolor" , 0.94902, 0.94902, 0.94902, 0.509804 ,
>> );
>
> This is working fine here (after removing the extra coma at the
> end). blue text flonum, without triangle, and almost half
> transparent white background as expected.
>
> ej
>
>


June 3, 2008 | 9:57 pm

On 3 juin 08, at 23:47, mattyo wrote:

> I think I had accidentally put the js out of the searchpath, and it
> was not recompiling properly — it all seems fine now.
>
> But while I’m on the topic, let me ask this: I’m trying to create a
> bunch of messageboxes with a different index in each, so that they
> would appear as [set 0 $1] [set 1 $1] etc, using an incrementing
> index in the js to get the changing value. However, you can’t
> format that using the @text attribute, as the middle value is a
> variable, and
>
> @text "set", v, "$1"

Did you try … "@text", "set " + v + " $1"?

ej


June 4, 2008 | 1:49 pm

>>
>>
>
> Did you try … "@text", "set " + v + " $1"?

Yes, I got message boxes containing only the symbol "set"


June 4, 2008 | 2:02 pm

I stand corrected — don’t make assumptions about yesterday’s code pre-
coffee….

I was using commas instead of pluses, which was not happening, but
this works perfectly. Thanks very much.

M

On Jun 4, 2008, at 9:49, mattyo wrote:

>
>>>
>>>
>>
>> Did you try … "@text", "set " + v + " $1"?
>
>
> Yes, I got message boxes containing only the symbol "set"


June 4, 2008 | 2:06 pm

On 4 juin 08, at 15:49, mattyo wrote:

> Yes, I got message boxes containing only the symbol "set"

This works for me:

var i = 12;
this.patcher.message("script", "newobject", "message",
"@patching_rect", 10, 10, 130, 20,
"@presentation", 1,
"@text", "set " + i + " $1"
);

Best,
ej


June 4, 2008 | 2:09 pm

On 4 juin 08, at 16:02, mattyo wrote:

> I was using commas instead of pluses, which was not happening, but
> this works perfectly. Thanks very much.

Right, you need the plus to use the string concatenation mechanism of
JavaScript, and pass only one string as argument for the "@text"
attribute. I’m glad it works.

There’s a few examples like that in the "Re-purposing Plug-ins in Max
5" tutorial on the website.

ej


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