How to save objects generated inside a JS within Live (set, presets)
Hello everyone,
I'm working on a patch for the Launchpad which uses a js object to create and manipulate an array (with no fixed size) of pages, each containing an array of custom objects of this kind:
var Control = function(x1,y1,x2,y2) {
this.x1 = x1;
this.x2 = x2;
this.y1 = y1;
this.y2 = y2;
this.drawControl = function() {
for (var x=x1;x
for (var y=y1;y
outlet(0,"led","matrix","set",x,y,1);
}
}
}
}
I would like to store these object into the patch when I save it in a Live Set or as a preset, but I'm a little bit confused as it seems to me that I can't store this kind of objects inside a pattr. I think I have to use the declareattribute method but I'm not sure how.
Thanks in advance for any suggestion!
NeZ
ok actually I figured it out a way, but if I save a preset (or Live set) and reload it, Live crashes. Basically I take my nested arrays and encapsulate them inside a Object, send it to the pattr (with parameters set on), if I try to retrive the data everything go fine. The problem happens only if I recall the patch with the saved data (with a preset or Live set). Is it a bug or I'm doing it wrong? Here it is the patch:
and the js:
outlets = 2;
var Oggetto = function() {
this.lista = new Array();
this.lista["pino"] = "pane";
this.lista["poni"] = new Array();
this.lista["poni"].push(3);
this.lista["poni"].push("unz");
}
var o = new Oggetto();
function generate() {
outlet(0,o);
post("ooo");
}
function loadit(x) {
post(x);
post();
outlet(1,x);
}
I'm working on something similar. Pattr and js objects do not play nice. You're better off JSONing your object and storing the serialised string in pattr.
Thanks ST8, this looks like the best way! I'll give it a try!