remove/delete object with scripting/varname
Hello,
i m so bad to js:)
I m cant manage to have the proper code to delete objects created from js, with a varname attributed from an array.

This is the code for newdefault i m using :
function createobject() {
{
var i;
for (i=0;i<arguments.length;i++)
vbox[i+2] = arguments[i];
{ var input1 = vbox[5]
var input2 = 1000
var output1 = input1 + input2
}
var maxObj = p.newdefault(vbox,output1);
maxObj.listener = new MaxobjListener(maxObj, callbackFun);
maxObj.varname = vbox[3];
objects.push(maxObj);
}
Could someone put me on the right track for scripting the delete function, with dynamic varname as input? i guess i need to listen for the objects varnames in the patcher?
thx!
It depends how you like to track varnames, as Max will allow to create a new object with an already existing varname, but it will add a index to it.
So if you want a new object to be created even if you give the same varname as an already existing one, I guess you'll need to iterate the objects in your patch when you want to delete them.
Alternatively, if you like the already existing object to just be replaced by a new one, you could just store your list of existing objects in a JS dictionary or something and completely disregard the actual "varnames".
thxi kinda manage to get it working. with
function delete (name)
{
a = p.getnamed (name);
p.remove(a);
}
Another question, do we have in js the equivalent for "script replace newex" ?
(so it replaces an existing object by a new one)