remove objects from patch
Hi,
I am trying to remove all nsliders in a patch at start time (if the user happens to have saved them the last time around). Anyway, below is my code. I can identify the nsliders but Max crashes when I try to delete them with this.patcher.remove(obj).
I am probably missing something obvious, so any help would be much appreciated.
Thanks
-----------------------------------
autowatch = 1;
function bang() {
var o = this.patcher.firstobject;
while (o) {
var me = o.maxclass;
if(me == "nslider") {
post(me);
post();
this.patcher.remove(o);
}
o = o.nextobject;
}
}
Try using the apply() function to step through the objects rather than the firstobject and nextobject patcher properties. I think the problem with your code is that you are attempting to delete an object and then test if it still exists with the while() function. Not entirely sure why this crashes max though.
lh
autowatch = 1;
function bang() {
this.patcher.apply(killnslider);
}
function killnslider(obj) {
if (obj.maxclass == "nslider") {
this.patcher.remove(obj);
}
}
That seems to work. I need to read up on apply()... didn't know about it.
Thanks a lot.
You can also applydeep() to look through subpatches but then you need to update the remove() location to the current subpatch. Shouldn't be too tricky though.
lh