• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Random Unit Of Group

Status
Not open for further replies.
Hey guys,

a few ago when I did some mapping and used FirstOfGroup() it was always random.

Now when I use it it ALWAYS is the first unit when I test the same group.
I also changed my editor settings to NOT have fixed random values in the settings dialog.

Is there anything else I have to take care of?! Or did they change how FirstOfGroup() works?
 
Level 9
Joined
Jul 10, 2011
Messages
562
im not totally sure but i think FirstOfGroup() takes the unit matching the conditions and is the nearest (strange word^^) to the point they are set from (units in range for example)....if theres no point its the nearest of one of the corners (dont remember which one)....


could be totally wrong but i think it was something like that...

jassers help me :wink:
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
If you really want a random unit, use the BJ function (or an other custom one), or an other unit data structure.
Nobody knows how exactly a group is filled when a GroupEnum is called.
Now maybe when you add manually an unit with GroupAddUnit, the relative order is kept, but i'm not sure at all.

And yes FirstOfGroup should return always the same unit if you don't add/remove units between calls of this functions.
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
Troll-Brain thanks for your answer.
I was talking about multiple test games of the same map and it kept selecting the same units as FirstOfGroup when I enum them on map.

Surprisingly the unit is NOT the closest to the location, but bottom right to the desired location.

Now try with different units rawcodes, or even different unit positions, i guess that the result shouldn't be always the same.
IIRC everybody failed to find something reliable, we just don't know how units are sorted in the group through a GroupEnum call.
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
It would be much better to use an unit array instead of a second group.
Now, frankly the BJ count function or a custom one should be good enough in almost cases.
Even if yeah ForGroup is much more inefficient because it opens a new thread for each unit in the group.

But this solution is less verbose, especially if you need to keep the group.
 
Status
Not open for further replies.
Top