wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Resources > Code Resources > Scripts
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 01-11-2009, 11:37 AM   #1
ToukoAozaki
extends net.wc3c.Jasser
 
Join Date: Jun 2008
Posts: 336

Submissions (5)

ToukoAozaki will become famous soon enough (60)ToukoAozaki will become famous soon enough (60)ToukoAozaki will become famous soon enough (60)

Send a message via MSN to ToukoAozaki
Default EnumUtils

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.
Collapse Example Code:
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.

Expand Library Code (.execute):

Expand Library Code (.evaluate):

Last edited by ToukoAozaki : 01-11-2009 at 06:11 PM.
ToukoAozaki is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 01-11-2009, 12:15 PM   #2
DioD
obey
 
DioD's Avatar
 
Join Date: Feb 2006
Posts: 1,532

Submissions (4)

DioD is a jewel in the rough (220)DioD is a jewel in the rough (220)DioD is a jewel in the rough (220)DioD is a jewel in the rough (220)

Send a message via ICQ to DioD
Default

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.
DioD is offline   Reply With Quote
Old 01-11-2009, 12:23 PM   #3
ToukoAozaki
extends net.wc3c.Jasser
 
Join Date: Jun 2008
Posts: 336

Submissions (5)

ToukoAozaki will become famous soon enough (60)ToukoAozaki will become famous soon enough (60)ToukoAozaki will become famous soon enough (60)

Send a message via MSN to ToukoAozaki
Default

Quote:
Originally Posted by DioD
BJ Style?

I dont see any clean up functions.

Looks like units stay in group forever.

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.
ToukoAozaki is offline   Reply With Quote
Old 01-11-2009, 02:25 PM   #4
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,898

Submissions (37)

Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)

Hero Contest #3 - 2nd Place

Default

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.
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 01-11-2009, 02:57 PM   #5
ToukoAozaki
extends net.wc3c.Jasser
 
Join Date: Jun 2008
Posts: 336

Submissions (5)

ToukoAozaki will become famous soon enough (60)ToukoAozaki will become famous soon enough (60)ToukoAozaki will become famous soon enough (60)

Send a message via MSN to ToukoAozaki
Default

Quote:
Originally Posted by Vexorian
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.

Just a question of curiosity. Would it be faster than BJ functions?

Last edited by ToukoAozaki : 01-11-2009 at 02:58 PM.
ToukoAozaki is offline   Reply With Quote
Old 01-11-2009, 03:07 PM   #6
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,898

Submissions (37)

Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)

Hero Contest #3 - 2nd Place

Default

It would probably be slower when there are a lot of units.
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 01-11-2009, 04:14 PM   #7
ToukoAozaki
extends net.wc3c.Jasser
 
Join Date: Jun 2008
Posts: 336

Submissions (5)

ToukoAozaki will become famous soon enough (60)ToukoAozaki will become famous soon enough (60)ToukoAozaki will become famous soon enough (60)

Send a message via MSN to ToukoAozaki
Default

Quote:
Originally Posted by Vexorian
It would probably be slower when there are a lot of units.

Hmm... How much performance improvement do you expect if the code is changed to ".evaluate" instead of ".execute"?
ToukoAozaki is offline   Reply With Quote
Old 01-11-2009, 04:43 PM   #8
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,898

Submissions (37)

Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)

Hero Contest #3 - 2nd Place

Default

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?
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 01-11-2009, 04:56 PM   #9
ToukoAozaki
extends net.wc3c.Jasser
 
Join Date: Jun 2008
Posts: 336

Submissions (5)

ToukoAozaki will become famous soon enough (60)ToukoAozaki will become famous soon enough (60)ToukoAozaki will become famous soon enough (60)

Send a message via MSN to ToukoAozaki
Default

Quote:
Originally Posted by Vexorian
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?

That seems to be a good idea.
ToukoAozaki is offline   Reply With Quote
Old 01-11-2009, 05:56 PM   #10
Rising_Dusk
Obscurity, the Art


Projects Director
Project Leader: OD
 
Join Date: Feb 2006
Posts: 9,729

Submissions (27)

Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)

Hero Contest #3 - 1st PlaceApproved Map: Desert of ExileApproved Map: Advent of the ZenithHero Contest #2 - 1st PlaceHero Contest - Third place>

Send a message via AIM to Rising_Dusk Send a message via MSN to Rising_Dusk
Default

Please do not make your functions public, but instead make them neither public nor private. The SCOPEPREFIX_ overhead makes this very painful to use.
__________________
Rising_Dusk is offline   Reply With Quote
Old 01-11-2009, 06:06 PM   #11
ToukoAozaki
extends net.wc3c.Jasser
 
Join Date: Jun 2008
Posts: 336

Submissions (5)

ToukoAozaki will become famous soon enough (60)ToukoAozaki will become famous soon enough (60)ToukoAozaki will become famous soon enough (60)

Send a message via MSN to ToukoAozaki
Default

Quote:
Originally Posted by Rising_Dusk
Please do not make your functions public, but instead make them neither public nor private. The SCOPEPREFIX_ overhead makes this very painful to use.

Okay, fixed. BTW I thought keeping function names themselves shorter would be enough, but it seemed a bit long when I saw it again.
ToukoAozaki is offline   Reply With Quote
Old 01-11-2009, 06:09 PM   #12
Rising_Dusk
Obscurity, the Art


Projects Director
Project Leader: OD
 
Join Date: Feb 2006
Posts: 9,729

Submissions (27)

Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)

Hero Contest #3 - 1st PlaceApproved Map: Desert of ExileApproved Map: Advent of the ZenithHero Contest #2 - 1st PlaceHero Contest - Third place>

Send a message via AIM to Rising_Dusk Send a message via MSN to Rising_Dusk
Default

Awesome, this is very useful now. Good job.
__________________
Rising_Dusk is offline   Reply With Quote
Old 01-11-2009, 06:22 PM   #13
ToukoAozaki
extends net.wc3c.Jasser
 
Join Date: Jun 2008
Posts: 336

Submissions (5)

ToukoAozaki will become famous soon enough (60)ToukoAozaki will become famous soon enough (60)ToukoAozaki will become famous soon enough (60)

Send a message via MSN to ToukoAozaki
Default

Does anyone know whether ForceEnumPlayers works without a genuine force? I just thought I could add something like EnumPlayersInForce.
ToukoAozaki is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 10:04 AM.


Affiliates
The Hubb The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

Powered by vBulletin (Copyright ©2000 - 2019, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services