1. Hey! Guest! The 32nd GMC Jam will take place between Feb 22nd, 12:00 UTC (Friday noon) and Feb 25th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

Once enemy hp<=0 kills a random enemy of same type

Discussion in 'Programming' started by MCretard, Jan 18, 2019.

  1. MCretard

    MCretard Member

    Joined:
    Jan 18, 2019
    Posts:
    2
    this is my code:

    with (o_tear) // the bullet
    {
    if (place_meeting(x,y,o_e_clone)) // the enemy
    {
    other.hp-=o_p_isaac.damage; // player damage
    instance_destroy()
    }
    }

    if (hp<=0) dead=true;
    if (dead)
    {
    instance_create_layer(x,y,"pickups",o_pa_tear_up) // damage multiplier
    instance_destroy()
    }

    in create:
    hp=5;
    dead=false;

    once hp<=0 kills a random enem of same type, how to fix
     
  2. NeZvers

    NeZvers Member

    Joined:
    Mar 24, 2018
    Posts:
    217
    Where are these things happening in code?
    Code:
    if (hp<=0) dead=true;
    if (dead)
    {
    instance_create_layer(x,y,"pickups",o_pa_tear_up) // damage multiplier
    instance_destroy()
    }
    
     
  3. NightFrost

    NightFrost Member

    Joined:
    Jun 24, 2016
    Posts:
    1,514
    That's the enemy step code right? Your problem is the with-block. It basically says: when the bullet is in contact with ANY enemy, decrease the hp of the enemy CURRENTLY running the code, and destroy the bullet. So, the enemy that takes the damage is the one GM first picks up to run, which tends to go in creation order.

    (There's also bit of inefficiency there, since the code runs on every enemy. The bullet instead should be doing the collision checking, so it only happens once per bullet per step.)
     
    MCretard likes this.
  4. MCretard

    MCretard Member

    Joined:
    Jan 18, 2019
    Posts:
    2
    thanks for the help. it's working good now.
     

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