Windows bug with draw event

T

Teomant

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

Teomant

Guest
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;
 
I

icuurd12b42

Guest
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 :)
 
T

Teomant

Guest
"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;
}
 
I

icuurd12b42

Guest
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.
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);
}
 
Top