creating and deleting multiple objects


    Feb 16 2007 | 1:18 am
    Hi,
    i am working on a project that requires objects to be dynamically created and removed from a patch. (for sake of simplicity i have made this object a simple '+' object here)
    my javascript works as i expect if i make all of the objects first (using the 'create_generation_no(a)' funtion and then use the 'kill_gen(x)' function to remove them. (each object created should live in an individual address in the 'generation_object' array)
    but
    if i make some objects, then remove them, and then create some more, the new ones can be removed using the 'kill_gen(x)' function using the array address's that i have already created and removed.
    what i want is that every new object is labelled individualy with no repeating so objects can be created and removed in any order..
    as i am just learning javascript i assume i am missing a fundamental point with the variables and array??
    any tips appreciated.
    thanks andrew
    -------patch--------
    ---------new_object.js--------
    // inlets and outlets
    inlets = 1; outlets = 1;
    // // global variables //
    var generation_object = new Array(1000); var position = 15
    // //create a new object labelled by generation number //
    function create_generation_no(a) { y = arguments[0]; post(y); post(); generation_object[y] = this.patcher.newdefault(500, position, "+", y); post(generation_object[y]); position = position+18; outlet(0, "bang"); if (position > 750) { (position = 15); }
    }
    // // delete an object by generation number index - if statement checks if it exists //
    function kill_gen(x) { a = arguments[0]; post(a); post(generation_object[a]); post(); if(generation_object[a]) this.patcher.remove(generation_object[a]);
    }
    // //reset //
    function reset() { position = 15; }