• Hey! Guest! The 37th GMC Jam will take place between May 28th, 12:00 UTC and June 1st, 12:00 UTC. Why not join in! Click here to find out more!

Problems Destroyiong Persistent Objects

mdbussen

Member
I'm having a kind of strange problem at the moment that I cannot quite figure out. I am trying to destroy some of the instances in my room and it SEEMS like they should be getting destroyed but for some reason they are not. These instances are all persistent, if that matters. Here is the relevant code snippet:

Code:
// create a ds_list of every instance id except for this one and the GUI object
var instance_list = ds_list_create();
for (var instance_index = 0; instance_index < instance_count; instance_index++){
    var this_id = instance_id_get(instance_index);
    if (this_id != id) and (this_id.object_index != asset_get_index("obj_gui")){
        ds_list_add(instance_list, this_id);
    }
}

show_debug_message("instance count before purging = " + string(instance_count));
show_debug_message("found " + string(ds_list_size(instance_list)) + " extraneous objects to destroy");

// blow away all of the non-obj_game_manager instances
for (instance_index = 0; instance_index < ds_list_size(instance_list); instance_index++){
    this_id = ds_list_find_value(instance_list, instance_index)
    show_debug_message("Destroying instance " + string(this_id));
    instance_destroy(this_id);
}

show_debug_message("instance count after purging = " + string(instance_count));
show_debug_message("instances left:");
for (var i = 0; i < instance_count; i++){
    show_debug_message(string(instance_id_get(i)));   
}
And here is what I am seeing on the console as a result of this code running:

Code:
instance count before purging = 6
found 4 extraneous objects to destroy
Destroying instance 100004
Destroying instance 100000
Destroying instance 100001
Destroying instance 100005
instance count after purging = 6
instances left:
100004
100000
100001
100002
100003
100005
Any idea what I am doing wrong here? o_O
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Check for the instances one step after the code has been run as (iirc) it takes one step for the instance to be removed from the room, even though the destroy event has been called in the previous step.
 
Top