• 🏆 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] Why using UnitIndex?

Status
Not open for further replies.
Level 22
Joined
Sep 24, 2005
Messages
4,821
You mean in unit indexers? Well, because you can't use the handle ids directly as array indices, that's why.
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
That's not an array though. I was talking about arrays... The point of unit indexers is to maximize code execution speed.

EDIT: To answer the question: Yes, you can do that.
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
as chobibo said, Unit indexer gives your units a values from 0 to 8191(maybe higher, but you will never have 8000 units in one map). This is made to maximize speed, therefore use arrays. GetHandleId returns handleid of given handle. It is also unique, but for agents(unit is agent) the returned value starts at 0x100000(roughly 1.4 million). You cant use 1,400,000 inside array :D
 

Bannar

Code Reviewer
Level 26
Joined
Mar 19, 2008
Messages
3,140
GetHandleId returns pretty big value, 0x100000++ (for agents), thus you can not operate with arrays since thier max index value is 8191. Arrays are fast, we like to use them.
Indexer manages and assigns unique index for every unit on the map ranging from 1 to 8191. You can use that to your advantage in numerous ways. They also provide _INDEX/ _DEINDEX event adding more convenient enter/leave events.

Basically, you do not need UnitIndexer if you don't want to. Unique handle id for each unit allows you to create MUI spells and systems anyway. Although, to gain some efficiency, it's good to have one within a map.

Look in jass section or spell section for examples of why and how you can use UI to your advantage.

Edit: In between another posts, was writing :p
 
Level 15
Joined
Aug 7, 2013
Messages
1,337
Thanks for asking this question Geshishouhu, it helped me a lot in understanding the purpose behind a UnitIndexer, and I was thinking of creating a similar thread too.

So the gist is that unit indexer gives a performance boost to code that requires MUI, if I understand correctly.
 
Level 11
Joined
Oct 11, 2012
Messages
711
Thanks for asking this question Geshishouhu, it helped me a lot in understanding the purpose behind a UnitIndexer, and I was thinking of creating a similar thread too.

So the gist is that unit indexer gives a performance boost to code that requires MUI, if I understand correctly.

You are welcome, sethmachine. :)
I think your understanding is correct. With Unit Indexer it comes with performance boost and maybe more convenient coding.
You may also find this post helpful http://www.hiveworkshop.com/forums/...x-unit-indexer-248209/index6.html#post2562752 because there are so many Unit Indexers systems around. Credit goes to Bannar.
 
Status
Not open for further replies.
Top