Problems Destroyiong Persistent Objects

Discussion in 'Programming' started by mdbussen, Nov 19, 2017.

  1. mdbussen

    mdbussen Member

    Joined:
    Jul 8, 2016
    Posts:
    62
    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
     
  2. Nocturne

    Nocturne Friendly Tyrant Forum Staff Admin

    Joined:
    Apr 13, 2016
    Posts:
    6,892
    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.
     
    mdbussen likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice