HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Units inside UnitGroups

12-30-2008, 01:09 PM#1
chobibo
I was experimenting with unit groups just now and I noticed that they are sorted. What I'm not sure is if they are sorted ascending via their handle Id.

What I've already tested is create 3 units, a, b, c. I then added those units (using GroupAddUnit native) in this order: c, a, b; I was expecting FirstofGroup to return c, but what it actually returned was a, I then looked at the handle Id's of a, b, and c, as it turns out, a's handle Id has the smallest value of the three.

Can anyone confirm this with any links or anything? Thanks!

Another question, does ForGroup callbacks allow Sleeps in them? I kinda used a sleep on a ForGroup inside a timer callback and the ForGroup callback failed, I was assuming that this was because the ForGroup was called inside the timer callback.

EDIT: Oh I forgot to mention that I tried searching for it already, I'm unsuccesful in finding anything related to my inquiry, maybe I'm using a wrong search keyword, I dunno.
12-30-2008, 01:45 PM#2
Captain Griffen
Research it. Add to the knowledge pool. The inner workings of groups are quite odd. See how it works with recycled handle indexes, etc.

Quote:
Another question, does ForGroup callbacks allow Sleeps in them? I kinda used a sleep on a ForGroup inside a timer callback and the ForGroup callback failed, I was assuming that this was because the ForGroup was called inside the timer callback.

No.
12-30-2008, 02:01 PM#3
emjlr3
Quote:
inside a timer callback

you cant use sleeps inside a timer callback period
12-30-2008, 02:32 PM#4
chobibo
Yes I already know that I can't use sleeps inside timer callbacks, I just didn't know that I also can't us them on ForGroup callbacks. Anyway thanks to the both of you, I'll try researching some more, the only thing I've used is GroupAddUnit and it sorts the units inside the group using the unit's handle Id's, I'll try the Circel enum functions now.

EDIT: I didn't get the pattern.

I lack the brain to do stuff like these, I think I'll stop testing for now lol. Anyways thanks.

Captain Griffen was right, groups behave oddly when using recycled ids.
12-30-2008, 04:08 PM#5
Troll-Brain
Yeah an other smart useless thing, i will make some tests with the groups.
12-30-2008, 04:25 PM#6
chobibo
Thanks Troll-Brain, apparently I was wrong in my guess that units were sorted via handle Ids, when I tried using recycled ids, I got random sequences, maybe it's an internal storage system, maybe a stack for units, I dunno.
12-30-2008, 05:48 PM#7
Troll-Brain
Hmm i tested with the EnumUnitInRange, hf to find a link :p
Attached Files
File type: w3mEnumRangeTest.w3m (14.6 KB)
12-30-2008, 06:03 PM#8
chobibo
Well It's pretty random, I should edit some of my post so that no one would be confused since It was incorrect. I guess the only way to know is to see the internal workings of the group, which is impossible for me.

About the testmap, now I know it doesn't depend on the unit, I think it's randomly picking a unit, but again I'm confused and not sure. I still don't understand how group handles the units stored onto it.
12-30-2008, 06:48 PM#9
Troll-Brain
It can't be random, just pseudo random.
Btw i displayed the unit in order they were enumed, you could edit the code to add a calling ForGroup after, maybe the units will be in an other (logical) order but i don't think so.
12-31-2008, 12:28 AM#10
DioD
Well, to check randomness, enumerate same units many times to different groups and check its order via First of Group loop.

If at least one unit of 100 fail check - group sorting is random.
12-31-2008, 04:26 PM#11
chobibo
4 5
3
1 2

That's the order I get if I use 4 units, I tested 10 times, I always get that order. I also tested with recycled groups and I can't get a pattern, it's also randomly ordered, I tried both ForGroup and first of group, they seem to have the same order.

The order I got was:
new handles: 1, 2, 3, 4
recycled handles: 2, 3, 4, 1

there were other patterns but mostly 2 was first on the list.

Aren't handle Id's memory locations? what if the groups use pointers internally, there's no way for me to check that lol.

@ DioD: I tried what you suggested, but I tested on recycled units, I got 2 similar patterns from 35 tests. I used GroupAddUnit on the test. Also if I use it for the same units, the order doesn't change.

Anyways thanks for the information guys.
01-01-2009, 07:58 AM#12
Jazradel
I thought I ran a test and decided it was ordered by their map coordinates.

That wouldn't really make sense though, I must be forgeting the part where I realised how much my test sucked.
01-01-2009, 12:26 PM#13
Archmage Owenalacaster
This may be irrelevant, but you ought to be able to perform any number of tests quickly by automating the entire thing. Just spam DisplayTextToPlayer on a timer or even have it compare each new one to the previous, and have it tell if there's a match. Minimum user input necessary.

EDIT: Would Jazradel share with us his test map?
01-01-2009, 02:28 PM#14
Deaod
i have been testing a bit, but i dont get the pattern.

i attached my testmap. maybe ill do some more testing, in which case ill have to update it.

Commands

-test: first command you have to use when you want to start testing.
-order: uses a FirstOfGroup()-loop to display the order.
-cb: uses ForGroup() to display the order.
-recycle: recycles one unit. without having used -rotate at least once, it recycles the unit far to the left.
-rotate: cycles internal references.
-h2i: displays the handleid of all units. can take some parameters.

i suggest you look at the code inside the map for a better understanding. Im no good at explaining things.

Attached Files
File type: w3xGroupsTest.w3x (9.9 KB)
01-01-2009, 06:16 PM#15
Bobo_The_Kodo
FirstOfGroup usually picks units that were created first first ( if their handle id has not been recycled )

It can get annoying in an AoS or something, because you have to use a random unit in group variant for spells that target random units in range