#Turn-based combat end state - Combat ending when only one enemy is defeated!

4 messages · Page 1 of 1 (latest)

gentle pebble
#

Hi all! I've been working on a turn-based combat system, and I want to have the combat conclusion only when all enemies have a collective hp stat <= 0, however it keeps triggering only when one enemy dies. I tried setting up a with loop too, but that didn't work. Any idea what I should do?

lean willow
#

Could you do something like this?

var _all_enemies_dead = true;
with obj_battle_unit_enemy
{
  if hp > 0
  {
    _all_enemies_dead = false;
  }
}
if _all_enemies_dead
{
  // do your thing
}
else
{
  // do the other thing
}
rich sand
#

you could also try an "enemies defeated" variable that increases each time you kill and enemy and have a check for how many enemies there are at the start of the battle, and if enemies defeated >= to number of enemies then end the battle

copper haven
#

Yeah, what you are currently doing is exactly as you described; when a single enemy has less than 1 hp, you activate all those layers.

Literally all you need to do is a simple iteration over things like such


function my_victory_check() {
  var all_dead = true
  with(obj_battle_unit_enemy) {
    //this can only remain true if everything is dead
    all_dead = all_dead && hp <= 0
  }
  if all_dead {
    //your layer activation stuff
  } else {
    //set your function state
  }
}