pattrstorage and getvalueof(), how does it work?


    Feb 03 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:

    • Feb 04 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.
    • Feb 04 2007 | 4:31 pm