• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

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

M

MCretard

Guest
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
 
N

NeZvers

Guest
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()
}
 

NightFrost

Member
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.)
 
Top