• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

native GetUnitPointValue for indexing data structures

Status
Not open for further replies.
Level 15
Joined
Aug 7, 2013
Messages
1,338
Hi,

I noticed that
JASS:
 GetUnitPointValue
seems pretty useful, since you can set the unit point value in the object editor and make a 1-1 correspondence with a unit and its point value.

But the parameter it asks for is a unit, not the unitTypeId. Is there a way around this, or would I have to create a unit based on the unitId, then call GetUnitPointValue to get the unit's point value, and then destroy the unit to avoid leak? That would be two native function calls, plus a destroy call and a setting variable.

The other way I was doing it was using a hash table to map the unitTypeIds to unique integer values (e.g. 0 - 150, each is a unique int for each unique hero type).

What is best to do?
 
Level 15
Joined
Aug 7, 2013
Messages
1,338
Use a unit indexer. It gets and sets the units user data.

Creating any unit creates a small leak even when they are removed.

It is best to use unit indexer or use a hashtable with either GetHandleId or UnitTypeId

Unit indexer is faster than hashtable.

This so-called unit indexer indexes what? I need a subset of all the custom unitTypeIds indexed for the range [0, |my subset|)

That's a shame GetUnitPointValue only works on instances of units when the point value is immutable and defined in the object editor! I don't see why it takes an instance over the unitTypeId, or at least it should have a shadowed method for the other possible argument.
 
Level 15
Joined
Aug 7, 2013
Messages
1,338
I said above what it does.


The unit user data is that units custom value.

Not exactly sure what you mean by a subset with those values...
What are you trying to do ?

I don't want to index every unit, just say all my custom heroes. Wouldn't the indexer need then to have each unitTypeId that represents one of these custom heroes manually added?
 
No it does not need that. It indexes any unit that is created.
It then attaches a custom integer to that unit to be read later for spells / systems.
It uses the Custom Value of that unit. Also known as Unit User Data.
When unit dies it de-indexes them.

There are many ways to index.

It would help if you explain more on what you are looking to do...
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
OP does not want to index individual units but the types from object editor.

There is also native GetUnitPointValueByType takes integer unitType returns integer

But yeah, why would you do it that way? If you set the point values manually in the object editor, you have to keep the overview over all the ids, the object editor does not have functions to help you there. And it's raw work. Then you can as well write jass init lines in a single page and the id allocation happens ingame from sequential calls. If you write some automatic script that distributes ids among the existing objects, you can as well generate jass init lines rather than fiddling with the object editor.

The only gain from stating it in the object editor is that you can instantly access it from anywhere as soon as the game starts.
 
Level 15
Joined
Aug 7, 2013
Messages
1,338
OP does not want to index individual units but the types from object editor.

There is also native GetUnitPointValueByType takes integer unitType returns integer

But yeah, why would you do it that way? If you set the point values manually in the object editor, you have to keep the overview over all the ids, the object editor does not have functions to help you there. And it's raw work. Then you can as well write jass init lines in a single page and the id allocation happens ingame from sequential calls. If you write some automatic script that distributes ids among the existing objects, you can as well generate jass init lines rather than fiddling with the object editor.

The only gain from stating it in the object editor is that you can instantly access it from anywhere as soon as the game starts.

Well I would also gain some space / performance if these calls are lightning fast, because then I wouldn't need a data structure to map unitTypeIds to their unique index, as I can just call
JASS:
 GetUnitPointValueByType
.

Originally I had been using a hash table to do that.

Well do you have a pointer to a tutorial for writing scripts to mass create objects in Warcraft 3 editor?

But no matter which way I go, I'll need to specify arbitrarily the index of each unit, either in a jass line or by the UnitPointValue...
 
Status
Not open for further replies.
Top