Counting Units

futeki

Active Member
Reaction score
4
What's the best way to count units?

Is there a better way to do it than this?:
Trigger:
  • Actions
    • Set TempGroup = (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to Villager))
    • Set UnitCountInt = (UnitCountInt + (Number of units in TempGroup))
    • Custom script: call DestroyGroup(udg_TempGroup)
 

Weep

Godspeed to the sound of the pounding
Reaction score
400
If you're not doing that action many times per second, that's fine. I'm a little confused why you're adding the count to the previous value of the count, however.

You might want to include the condition that the units are alive, or it will also count corpses.
 

futeki

Active Member
Reaction score
4
If you're not doing that action many times per second, that's fine. I'm a little confused why you're adding the count to the previous value of the count, however.

It's a recurring event, that takes place every 2 minutes. I suppose I should post more of the trigger, I'm trying to get a fresh count of the units on the map. Here's the other part of the trigger:

Trigger:
  • Actions
    • Set UnitCountInt = 0
    • Set TempGroup = (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to Villager))
    • Set UnitCountInt = (UnitCountInt + (Number of units in TempGroup))
    • Custom script: call DestroyGroup(udg_TempGroup)


You might want to include the condition that the units are alive, or it will also count corpses.

I have a trigger with an event so when a unit dies, it removes that unit. Pretty sure that fixes that problem. No?
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
i wouldnt recommend this method for periodic events.

just have an integer value increase each time a villager is created and have it decreased each time a villager is removed/killed/whatever.
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
that its running periodically. thats all.

its running even though it is not needed. waste of performance and energy not any more then that.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top