Forums > Javascript

pattrstorage and getvalueof(), how does it work?

February 3, 2007 | 11:52 am

Hi,

From what I read in the docs, I believe it is possible to store and recall a value of a js with pattrstorage by defining a getvalueof and setvalueof function. Is that correct?

I’ve been trying, but with no succes. Store and recall don’t work, I don’t see any reference in the clientwindow, and the saved xml file is empty.

If anyone has a hint how to do this, I would be very grateful.

Mattijs

I use the following patch and script to test:

——– save as pattrbindtest.js:

autowatch = 1;

var myvalue = 0.25;

function getvalueof()
{
return myvalue;
}

function setvalueof(v)
{
myvalue = v;
notifyclients();
}

function msg_int(v)
{
myvalue = v;
}

function bang()
{
post("myvalue: " + myvalue);
post();
}

function printThis()
{
for (var property in this)
{
post(property)
post();
}
}

——– patch:

#P number 39 128 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P message 62 32 14 9109513 1;
#P message 22 32 37 9109513 store 1;
#P message 62 51 14 9109513 2;
#P message 22 51 37 9109513 store 2;
#P message 104 148 51 9109513 printThis;
#P newex 22 87 58 9109513 pattrstorage;
#X client_rect 15 55 655 295;
#X storage_rect 0 0 640 240;
#P objectname u811000042;
#P button 22 128 15 0;
#P newex 22 148 80 9109513 js pattrbindtest.js;
#P objectname js;
#P connect 4 0 2 0;
#P connect 5 0 2 0;
#P connect 6 0 2 0;
#P connect 7 0 2 0;
#P connect 8 0 0 0;
#P connect 3 0 0 0;
#P connect 1 0 0 0;


February 4, 2007 | 12:14 pm

On 03 Feb 2007, at 12:52, Mattijs Kneppers wrote:
>
>>> From what I read in the docs, I believe it is possible to store
>>> and recall a value of a js with pattrstorage by defining a
>>> getvalueof and setvalueof function. Is that correct?
>
> I’ve been trying, but with no succes. Store and recall don’t work,
> I don’t see any reference in the clientwindow, and the saved xml
> file is empty.

my understanding is, that you have to add a pattr object to your
patch and connect/bindto the js object.
also i would suggest to move the notifyclients() message from the
setvalue() function to your msg_int() function, as to "notify" pattr,
that myvalue has changed:

function msg_int(v) {
myvalue = v;
notifyclients();
}

hope that helps
- volker.


February 4, 2007 | 4:31 pm


February 4, 2007 | 4:36 pm


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