Getting all the units inside of a region in specific order

cmann

New Member
Reaction score
1
Basically I'm getting all the units in a region and looping through them with something like this:

JASS:

set g = GetUnitsInRectAll( region )
set unitCount = CountUnitsInGroup(g)

loop
  exitwhen a == unitCount

  set u=FirstOfGroup(g)
  call GroupRemoveUnit(g, u)

  set a = a + 1

endloop


What I also need is to get the units in a specific order.
Now the code above actually works most of the time, it will give me the units in the order that I created them inside the World Editor.
The problem is that sometimes it doesn't work, for example maybe two units get swapped around.

Does anybody know why it does this and how I could get around this or if there is another way to do this that will ensure that the units are given to me in the same order that I create them?
 

Sim

Forum Administrator
Staff member
Reaction score
534
If you really want to get the units in the correct order, assign each of them to a unit array, and when you loop through the unit array again, loop in the same order that you assigned them.

It should always pick them in the right order then.

Of course, check if they're in the rect at the time you assign them to the unit array.
 

cmann

New Member
Reaction score
1
That won't work either.
I want to take them from the region and then add them to an array.
 

Sim

Forum Administrator
Staff member
Reaction score
534
That's not what I meant. The UnitArray process is to "recreate" the order the World Editor created the units, without the bug.

Thus, assign them to the array at the time when they are created in the World Editor.

set UnitArray[whatever] = CreateUnit(...)

then when it's the time to loop, loop through the UnitArray exactly as you did above, by counting the units in the region, but since the array preserves the exact order they were created in the editor as opposed to depending on the editor to recall the order, it should work.
 

cmann

New Member
Reaction score
1
OK. I get what you're saying but it kind of defeats the whole point of getting them from the region in the first place.
The whole point of getting the units from a region was to avoid creating the array by hand, using Array[index]=CreatUnit()...
 
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