![]() |
#1 |
extends net.wc3c.Jasser
|
![]() When I was writing code with GroupEnumUnitsXXX natives, I found out that they require a valid group parameter. Creating temporary group every time whenever I needed to enum units was definitely messy. Otherwise, I had to use globals block to define a single private dummy group for each library. So I came up with the idea of writing a library that contains every element needed.
This library greatly simplifies process to enum units. You don't have to worry about anything about groups. It also eliminates the need of creating a filter every time (or defining a global for it). Using it is extremely easy. All you need is a callback function that matches the signature. You can see it in the example below. ![]() function MyCallback takes unit u returns nothing call BJDebugMsg(GetUnitName(u)) // print name endfunction // straightforward call EnumUnitsOfPlayer(GetTriggerPlayer(), MyCallback) Very simple, isn't it? There are two styles: .execute and .evaluate. The only difference is one line of code, but you should be aware of the differences: .execute style allows waits inside callbacks, while .evaluate style runs faster but doesn't allow waits inside callbacks. ![]() ![]() Last edited by ToukoAozaki : 01-11-2009 at 06:11 PM. |
![]() |
![]() |
Sponsored Links - Login to hide this ad! |
|
![]() |
#2 |
obey
|
![]() BJ Style?
I dont see any clean up functions. Looks like units stay in group forever. Last edited by DioD : 01-11-2009 at 12:21 PM. |
![]() |
![]() |
![]() |
#3 | |
extends net.wc3c.Jasser
|
![]() Quote:
They don't. Actually, they aren't even added to the group. Filter function EnumerateUnits always returns false no matter what the unit is, and units are added when filter function returns true. Last edited by ToukoAozaki : 01-11-2009 at 12:27 PM. |
|
![]() |
![]() |
![]() |
#4 |
Free Software Terrorist
Technical Director
|
![]() Not bad actually.
__________________The only problem is that it performs worse than doing the enums yourself. But this should simplify code for cases where you only need one small enum in rare times so that performance is not worth the code bloat. |
![]() |
![]() |
![]() |
#5 | |
extends net.wc3c.Jasser
|
![]() Quote:
Just a question of curiosity. Would it be faster than BJ functions? Last edited by ToukoAozaki : 01-11-2009 at 02:58 PM. |
|
![]() |
![]() |
![]() |
#6 |
Free Software Terrorist
Technical Director
|
![]() It would probably be slower when there are a lot of units.
__________________ |
![]() |
![]() |
![]() |
#7 | |
extends net.wc3c.Jasser
|
![]() Quote:
Hmm... How much performance improvement do you expect if the code is changed to ".evaluate" instead of ".execute"? |
|
![]() |
![]() |
![]() |
#8 |
Free Software Terrorist
Technical Director
|
![]() You use .execute? Well, the answer is 3x faster but it will still be slower than BJ functions when you have plenty of units.
__________________Actually, .execute is very useful since it will allow you to have waits, so that's more of a reason to use these functions. Perhaps have versions for .evaluate and .execute? |
![]() |
![]() |
![]() |
#9 | |
extends net.wc3c.Jasser
|
![]() Quote:
That seems to be a good idea. |
|
![]() |
![]() |
![]() |
#11 | |
extends net.wc3c.Jasser
|
![]() Quote:
Okay, fixed. BTW I thought keeping function names themselves shorter would be enough, but it seemed a bit long when I saw it again. |
|
![]() |
![]() |
![]() |
#13 |
extends net.wc3c.Jasser
|
![]() Does anyone know whether ForceEnumPlayers works without a genuine force? I just thought I could add something like EnumPlayersInForce.
|
![]() |
![]() |
![]() |
Thread Tools | Search this Thread |
|
|