First of Group - Dealing with null units

Status
Not open for further replies.
Level 12
Joined
May 22, 2015
Messages
1,051
I have a group that gets looped over periodically and needs to be able to have units be added and removed at any time. The group must persist each time.

I ran into an issue where one of the units exploded from a meat wagon so it got set to null. This causes problem with:
JASS:
exitwhen picked == null

Is there any way to remove a null unit from a group?
Is there any way to check if there are still more units in the group that's not slow?

Or do I have to be super meticulous about removing the units as they die and whatnot?

I added a separate trigger to remove units from the group when they die, but I still eventually ran into the problem (basically the group just thinks it is empty forever - so adding units stops doing anything). It is hard to tell what happened that caused it.
 
Level 12
Joined
May 22, 2015
Messages
1,051
Ya I forgot to mention that in there as well. The loop is every second, so I don't know how big of a deal it is for that. The number of units in the group won't be super large, but if null units get stuck in there, the loop could get bigger and bigger over time - hitting all the nulls for no reason.

Is there a way I can remove those null units when I find them? I could just have a quick check to see if the unit is equal to null and then remove it and return.

I suppose maybe I could also just have it check for when all the units are null. It would be very rare, I think, for the group to have units in it at all times for a very long time, so when it sees that they are all null, it can clear the whole group.

Another solution popped into my head haha. If I add the units that are not null to another group and then swap them like normal (clearing the old group), then it will remove all the null units that way.

Any other ideas?
 
Status
Not open for further replies.
Top