[SOLVED] Help with Destroying a specific instance without destroying all in room

Discussion in 'Game Design, Development And Publishing' started by guitarmonkeys14, Feb 17, 2019.

  1. guitarmonkeys14

    guitarmonkeys14 Member

    Joined:
    Jan 19, 2019
    Posts:
    10
    Hey everyone, I am currently making a scrolling 2D top down shooter and I am stuck. I have been using a combination of DnD and GML so any help is greatly appreciated.

    I currently have the game set up to have random spawn points for my enemies. Basically boulders that are created out of view above the screen then scroll down the map with the ground. I then have an object spawn with the boulders that spawns the enemies. I already have the boulders set up to be destroyed when shot.

    My problem is that I cant get only the specific spawn point to destroy when that specific boulder's hp is less than 0. All of the other spawners on the map go with it. I have also tried if_instance_exists but nothing has worked so far. any suggestions?

    obj_ctrl_lvl_endless (Alarm event)

    Code:
    // Create Instance
    obj_newboulder2 = instance_create_layer(random_range(3000,200), -1000, "Instances", obj_boulder2);
    
    // Set Alarm Countdown
    alarm_set(2, random_range(300,600));
    
    // If Expression
    if(instance_exists(obj_newboulder2))
    {
       // Create Instance
       tempzombie1 = instance_create_layer(obj_newboulder2.x, obj_newboulder2.y-300, "Instances", obj_zombie1spawn);
    
       // Set Alarm Countdown
       alarm_set(2, random_range(300,600));
    
       // If Expression
       if(!(instance_exists(obj_newboulder2)))
       {
           // Destroy Instance
           with(temp) instance_destroy();
       }
    }
    
    obj_boulder (Collision with obj_laser)

    Code:
    // Assign Variable
    hp += -34;
    
    // Destroy Instance
    with(other) instance_destroy();
    
    // If Variable
    if(hp <= 0)
    {
       // Destroy Instance
       instance_destroy();
    
       // Destroy Instance
       with(obj_zombie1spawn) instance_destroy();
    }
    
    obj_zombie1spawn

    Code:
    // Create Instance
    instance_create_layer(x, y, "Instances", obj_zombie);
    
    // Set Alarm Countdown
    alarm_set(0, random_range(450,500));
    
    Any help would be greatly appreciated,

    Thank you in advance
     
  2. NeonBits

    NeonBits Member

    Joined:
    Sep 22, 2017
    Posts:
    348
    I wouldn't give me an headache; I would duplicate obj_spawner and make it obj_spawner1, 2, 3, etc.and do the same with the boulder; each boulder to its own respective spawner. Boring, I know, but I'm poor at coding and tired, meh.
    So when boulder1 is destroyed, you can simply say "with (obj_spawner1){instance_destroy();}"
     
  3. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    3,691
    Pass the boulder's instance ID to the spawn point when you create it.
    Code:
    //obj_ctrl_lvl_endless Alarm
    inst_newboulder2 = instance_create_layer(random_range(3000,200), -1000, "Instances", obj_boulder2);
    //...
    tempzombie1 = instance_create_layer(obj_newboulder2.x, obj_newboulder2.y-300, "Instances", obj_zombie1spawn);
    tempzombie1.inst_boulder = inst_newboulder2;
    
    Then set up a default in the spawn point's Create event and check it in the Step event:
    Code:
    //Create event
    inst_boulder = noone;
    Code:
    //Step event
    if (inst_boulder != noone && (!instance_exists(inst_boulder) || inst_boulder.hp <= 0)) {
      instance_destroy();
    }
    Then perhaps you shouldn't be giving advice on it.
     
  4. NeonBits

    NeonBits Member

    Joined:
    Sep 22, 2017
    Posts:
    348
    Meeooôôôwwwwww HIssss Hisssssssss...
    I'm kidding : D
    PUuUuuUuuuUUuuUUuRRrRRRrRRrRrRrRRrr
    How's my favorite Neko >^.^< ?
    Hey, maybe my suggestion is not from Einstein but it's better than advil.
    You know, a purr was enough if you wanted me to "chat" with ya - .^
     
    Last edited: Feb 17, 2019
  5. guitarmonkeys14

    guitarmonkeys14 Member

    Joined:
    Jan 19, 2019
    Posts:
    10
    Worked even more beautifully than a charm. Exactly what I was looking for, THANK YOU THANK YOU!
     

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