• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

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?
 
Level 19
Joined
Mar 18, 2012
Messages
1,716
Go with ForGroup, when you want to use the group handle.

As an alternative you can create a linked list and interate over that.
Add units ( add a node to the list ) whenever you need it.
Remove invalid units handles via GetUnitTypeId(whichUnit) == 0. ( remove that node from the list )
 
Status
Not open for further replies.
Top