Windows bug with draw event

Discussion in 'Programming' started by Teomant, Nov 17, 2018.

Tags:
  1. Teomant

    Teomant Member

    Joined:
    Nov 17, 2018
    Posts:
    3
    I wanted to make a display of HP bars only in combat. In the beginning HP bar are not visible, but it appear during the attack. But in the game on the very first enemy in the room the draw code does not work. His HP bar is always visible. And other manipulations with draw alpha also dont work for him. How to fix?
    sorry for my english
     
  2. icuurd12b42

    icuurd12b42 TMC Founder GMC Elder

    Joined:
    Apr 22, 2016
    Posts:
    1,837
  3. Teomant

    Teomant Member

    Joined:
    Nov 17, 2018
    Posts:
    3
    Draw code:

    if a >= 100 and combat == true {
    combattime -= 1;
    }
    else a = a + 1;
    line = ((maxhp - hp) * 100 / maxhp) / 4;
    draw_line_width_color(x-12.5,y-15,x+12.5,y-15,2,c_black,c_black);
    draw_line_width_color(x-12.5,y-15,x-line+12.5,y-15,2,c_red,c_red);
    if combattime <= 0 {
    combat = false;
    a = a - 2;
    }
    if a <= 0 {
    a = 0;
    }
    draw_set_alpha(a/100);
    draw_self();

    When attacked:
    parent.combat = true;
    parent.combattime = 300;
    player.combat = true;
    player.combattime = 300;
     
  4. icuurd12b42

    icuurd12b42 TMC Founder GMC Elder

    Joined:
    Apr 22, 2016
    Posts:
    1,837
    what is parent?
    an object poorly named?
    object.variable = something only sets the first instance of object... explaining why parent.combat = true; only turns on one instance to show the HP

    so try

    When attacked:
    with(parent)
    {
    combat = true;
    combattime = 300;
    }

    with(player)
    {
    combat = true;
    combattime = 300;
    }


    and name your objects properly :)
     
  5. Teomant

    Teomant Member

    Joined:
    Nov 17, 2018
    Posts:
    3
    "parent" - this is the parent of all enemies in the game.
    there's something wrong with numeration it i guess:
    Found another bug. When I attack an enemy with ID "1", the game considers that I hit the enemy with ID "2".
    The very first enemy is in the game, but the game does not think so.

    that's how I "naming" my enemies:
    weapon = instance_create_depth(x,y,depth,E_bandit_weapon_1);
    with weapon {
    parent = other;
    weaponattack = Bandit_Sword_Attack;
    weaponstand = Bandit_Sword;
    }
     
  6. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,469
    You should use other.id in this situation. other is a constant always equal to -2, and it loses context past the current piece of code if kept in a variable.
     
    Bentley and Nocturne like this.
  7. icuurd12b42

    icuurd12b42 TMC Founder GMC Elder

    Joined:
    Apr 22, 2016
    Posts:
    1,837
    That is no longer applicable in gms2. other (and self) now resolved to an id... so other.id would resolve to (100000).id... would resolve to 100000...

    object 0 create
    show_debug_message(id);
    show_debug_message(self);
    show_debug_message(self.id);
    with(instance_create_depth(0,0,0,object1))
    {
    show_debug_message(other);
    show_debug_message(other.id);
    }
     
    Dennis Ross Tudor Jr and Bentley like this.

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