GMS 2 Issue On EnemyHit and HP

Aegean

Member
Hi guys, I am having a problem in my rpg game. I found some opensource code and I didn't understand the "hp-" expression. Because of that I couldn't code my enemies hp and my game crashes when I hit them.


Code:
//EnemyHit//
var _damage = argument0;

hp- = _damage
flash = true;
if(hp > 0)
{
state = ENEMYSTATE.HIT;
hitNow = true ;
}
else {

state = ENEMYSTATE.DEAD;
})

Code:
// obj_enemy Create//
state = ENEMYSTATE.FREE;
 enum ENEMYSTATE{

   FREE,
   HIT,
   DEAD
}
 

CloseRange

Member
it's actually ususally written hp -= _damage;
it's a fancy way of writing
hp = hp - _damage;

they do the same thing but the first way is usally cleaner
 
Last edited:

FrostyCat

Member
The subtraction symbol goes with the = like this. When they go together, they cannot have a space in between.
Code:
hp -= _damage;
This decreases the value of the variable hp by damage.
 
Top