SC2Mapster.com Wiki

UnitIsAlive

bool UnitIsAlive(unit u);

Is the unit alive

This is most often used as a guard when you go over a unit group.

Parameters

unit u

Unit to check

Return value

bool -

  • true: the unit is alive
  • false: the unit is not alive (dead)

Examples

Example: Sample Usage
int UnitGroupCountAlive(unitgroup g) {
  unit u;
  int count = UnitGroupCount(g, c_unitCountAll);
  int countAlive = 0;

  // Iterate over all the units of the group
  while (count > 0) {
    count -= 1;
    u = UnitGroupUnit(g);

    // If the unit is alive then increment the counter
    if (UnitIsAlive(u)) {
      countAlive += 1;
    }
  }
  return countAlive;
}

// Note: This is only a function useful for demonstration, 
// you can do it faster using
// UnitGroupCount(g, c_unitCountAlive)

You must login to post a comment. Don't have an account? Register to get one!

Facts

Date created
Mar 10, 2010
Last updated
Mar 12, 2010

Author