• 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!

enemy health not subtracting properly

Hello! this is my first ever post on this form and I am also very new to this community!

I have a problem with my game that has been bugging me. I have this black hole bullet that's supposed to subtract the enemies (they are all connected to a parent object) health While the enemy is overlapping the bullet. its supposed to subtract the health from every enemy that is currently overlapping it every certain amount of ticks in an alarm.

problem is, it randomly finds exactly one enemy that's overlapping the bullet, subtracts the health and then finds another enemy and carries on. I want it to subtract the health from all enemies overlapping at the same time rather then picking up one and going to the next.

Here is my code if this helps:

Begin Step event in the bullet:

var bulletin = instance_place(x,y,obj_enemyParent);

if bulletin and bulletDamageTick = true and alarm[0] >= 6 {
bulletin.hp -= bulletDamage;
bulletin.flashWhite = true
audio_stop_sound(snd_enemyHit1);
audio_play_sound(snd_enemyHit1, 10, false);
}

- the obj_enemyParent has all the health properties and such stored inside, as well I have different properties for the bullet objects. the alarm resets itself to 7 after it reaches down 0. this is all what my alarm is doing but I don't think this is the issue. The alarm is only in the bullet object:


if bulletDamageTick {
alarm[0] = 7;
}

I'm very much new to this program and I'm still trying to figure things out. Any sort of help is appreciated!


 
look into instance_place_list(). It is in the manual.
instance_place() only ever works for one instance so to say.
Ah yes! I managed to get it to work with this!! Thanks for the help!

this is what I ended up doing. I'm sure it could use more optimizing, but this is what I have:

Code:
var _list = ds_list_create();
var _num = instance_place_list(x, y, obj_enemyParent, _list, false);

if _num > 0 and bulletDamageTick = true and alarm[0] >= 6 {
    for (var i = 0; i < _num; ++i;) {
        bulletin.hp -= bulletDamage;
        bulletin.flashWhite = true
        audio_stop_sound(snd_enemyHit1);
        audio_play_sound(snd_enemyHit1, 10, false);
        }
    }
ds_list_destroy(_list)
 
Top