Access to [coll] content from javascript code?

nickpic's icon

Hi,
Through a javascript code, is there a way I can access the content of a [coll]?

Thanks for your helps and hints!
NP

pdelges's icon

You need to give your [coll] a name. Then you can use it within JS code using [coll]'s message.

Here is an exemple (only some lines of code from a old project, so it is of course not working) with a table, called "intervalles". In function updateTable(), I empty the table and put new values in it.

var thePatcherTable ;

function loadbang ()
{
    thePatcherTable = this.patcher.getnamed("intervalles");
}

function updateTable()
{
    thePatcherTable.message ("clear");
    for (i=0; i
        thePatcherTable.message ("list", i, octave1[i] + offsetForTable);
    for (i=0; i
        thePatcherTable.message ("list", i+octave1Size, octave2[i] + offsetForTable);
    outlet (0, octave1Size + octave2Size);

}

pdelges's icon

Ooopps, something happened after I edited my message to correct a typo. I wish there was a preview. Here is the code again.

function loadbang ()
{
    thePatcherTable = this.patcher.getnamed("intervalles");
}
function updateTable()
{
    thePatcherTable.message ("clear");
    for (i=0; i
        thePatcherTable.message ("list", i, octave1[i] + offsetForTable);
    for (i=0; i
        thePatcherTable.message ("list", i+octave1Size, octave2[i] + offsetForTable);
    outlet (0, octave1Size + octave2Size);
}

Luke Hall's icon

With maxobj.message() you can't retrieve the already stored contents, only send a message to the object. To do this you'd probably need to script connections from the [coll] outlets to your [js] and then send the [coll] a "dump" message.

lh