Forums > Javascript

Can one notify pattrstorage of changes in js-attributes?

October 11, 2006 | 6:38 pm

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


October 11, 2006 | 9:20 pm

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…).


October 11, 2006 | 9:59 pm

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


October 12, 2006 | 11:10 am

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.


December 27, 2010 | 12:39 am

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


March 1, 2011 | 11:49 am

Works for me.

Attachments:
  1. jspattr.zip


ST8
March 1, 2011 | 12:30 pm

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


March 1, 2011 | 12:42 pm

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


March 1, 2011 | 12:44 pm

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


March 3, 2011 | 4:18 am

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


March 3, 2011 | 9:54 am

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.


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