Patcher properties example script


    Jan 21 2007 | 12:40 pm
    Hi, the example script provided in Basic Javascript programming -> Patcher properties -> box seems to be incorrect.
    It reads like this:
    prev = 0;
    owner = this.patcher.box;
    while (owner)
    {
    prev = owner;
    owner = owner.patcher.box;
    }
    if (prev)
    post("top patcher is",prev.name);
    But prev (being a Maxobj) doesn't have the propery 'name'. Also, the topmost patcher object doesn't return a 'box' property, so this loop quits one cycle too early.
    To reproduce:
    save as 'top.js':
    autowatch= 1
    outlets= 1;
    inlets=1 ;
    function top()
    {
    prev = 0;
    owner = this.patcher.box;
    while (owner)
    {
    prev = owner;
    owner = owner.patcher.box;
    }
    if (prev) post("top patcher is",prev.name);
    }
    This outputs in the max window: top patcher is
    Now try this for 'top.js':
    autowatch= 1
    outlets= 1;
    inlets=1 ;
    function top()
    {
    prev = 0;
    owner = this.patcher.box;
    while (owner)
    {
    prev = owner;
    owner = owner.patcher.box;
    post("prev: " + prev.subpatcher().name + ", new owner: " + owner);
    post();
    }
    if (prev) post("top patcher is", prev.name);
    }
    This returns:
    prev: yeah, new owner: undefined
    top patcher is
    Mattijs