Can one notify pattrstorage of changes in js-attributes?

Oct 11, 2006 at 6:38pm

Can one notify pattrstorage of changes in js-attributes?

I’ve got a js file with attributes declared by the declareattribute() function. Then I put into this patch an autopattr-object with greedy mode on, so I can see my attributes’ values with a pattrstorage object.

Now, the problem is: when I change the values of these attributes in my js-object I can’t get the pattrstorage to recognise that the value has changed. Notifyclients() doesn’t help. Only when I send a “grab” message to the pattrstorage object it gets the new attribute values.

This is the JS-file:
———————————————

var billy=0;

declareattribute(“billy”, “getbilly”, “setbilly”);

function setbilly(b)
{ notifyclients();
billy=b;
}

function getbilly()
{ return billy;
}

———————————————-

And then I have another question: is it possible, somehow, to give a string to a JS-object and make it create an attribute out of this string? For instance: I give it a message “add Color” and my JS-object would create a variable (and attribute) named Color.

Now that would be heavenly.

- Tarik

#28089
Oct 11, 2006 at 9:20pm

Quote: Tarik wrote on Thu, 12 October 2006 07:38
—————————————————-
> And then I have another question: is it possible, somehow, to
> give a string to a JS-object and make it create an attribute out
> of this string? For instance: I give it a message “add Color” and
> my JS-object would create a variable (and attribute) named Color.

Basically:

function add(str)
{
if(typeof str == “string”)
{
eval(“var ” + str + “;declareattribute(” + str + “)”);
}
}

No idea about the pattrstorage question, I don’t use it (must look into that sometime, er…).

#85842
Oct 11, 2006 at 9:59pm

Thanks and yes, you should!

The pattr world is a wonderful one. And I want to mention that of course “notifyclients()” should have come AFTER the “billy=b” statement in the example above. But that doesn’t really matter as far as the problem is concerned.

– T

#85843
Oct 12, 2006 at 11:10am

Thanks for the report. I can reproduce the problem and will investigate.

jb

Am 11.10.2006 um 20:38 schrieb Tarik:

> I’ve got a js file with attributes declared by the declareattribute
> () function. Then I put into this patch an autopattr-object with
> greedy mode on, so I can see my attributes’ values with a
> pattrstorage object.
>
> Now, the problem is: when I change the values of these attributes
> in my js-object I can’t get the pattrstorage to recognise that the
> value has changed. Notifyclients() doesn’t help. Only when I send a
> “grab” message to the pattrstorage object it gets the new attribute
> values.

#85844
Dec 27, 2010 at 12:39am

I have come up against this same issue, what was the verdict?

#85845
Mar 1, 2011 at 11:49am

Works for me.

Attachments:
  1. jspattr.zip
#85846

ST8
Mar 1, 2011 at 12:30pm

Ok, but what happens if you update the variable internally (within the js) and call notifyclients? I’m not getting an update in the pattr from that. Maybe im misunderstanding how this is supposed to work :)

quick example:

function increment() {
billy++
post(billy)
notifyclients()
}

if i put that in your js and call “increment”, the pattr is not updated

#85847
Mar 1, 2011 at 12:42pm

Do it like this:

this.box.message("billy", somevalue);

In fact, you can get rid of notifyclients() — it’s only used to tell pattr that the value of “billybox” has changed — the js object itself, not that its attributes have changed.

Jeremy

#85848
Mar 1, 2011 at 12:44pm

this.box.message("billy", billy + 1);

for your increment example.

It’s a bit ugly, but you have to basically send a message to the box. Otherwise, it doesn’t know that what you are changing is an attribute (the attribute is only relevant at the border of the Max and JS worlds).

Jeremy

#85849
Mar 3, 2011 at 4:18am

completely forgot about this post. Thank you.

I realized that solution a while back when something about pattr clicked and i realized that i could just have the pattr in the patch disconnected from everything else. set was no longer necessary and all was well

#85850
Mar 3, 2011 at 9:54am

I’ve got a js file with attributes declared by the declareattribute() function. Then I put into this patch an autopattr-object with greedy mode on, so I can see my attributes’ values with a pattrstorage object.

#85852

You must be logged in to reply to this topic.