1. Hey! Guest! The 35th GMC Jam will take place between November 28th, 12:00 UTC - December 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

enemy health not subtracting properly

Discussion in 'Programming' started by animated_ginger, Nov 8, 2019 at 7:17 PM.

  1. animated_ginger

    animated_ginger Member

    Joined:
    Oct 29, 2019
    Posts:
    6
    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!



     
  2. Simon Gust

    Simon Gust Member

    Joined:
    Nov 15, 2016
    Posts:
    3,198
    look into instance_place_list(). It is in the manual.
    instance_place() only ever works for one instance so to say.
     
    animated_ginger likes this.
  3. animated_ginger

    animated_ginger Member

    Joined:
    Oct 29, 2019
    Posts:
    6
    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)
     

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