• 🏆 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!

Indexing Questions

Status
Not open for further replies.
Level 22
Joined
Jul 25, 2009
Messages
3,091
So I'm doing a squad system, all of the information pertaining to each squad type is saved in a table like so:
Squad Setups
Events
Map initialization
Conditions
Actions
-------- Chaos Marauders --------
Set GLeaderIsDifferent[1] = False
Set GLeaderUnitType[1] = Chaos Marauder
Set GRealMaxSize[1] = 6
Set GCurrentMaxSize[1] = 6
Set GUpgradeItem01[1] = Chaos Chosen Marauder
Set GMoraleDamageAmount[1] = 1
-------- Chaos Warriors --------
Set GLeaderIsDifferent[2] = False
Set GLeaderUnitType[2] = Chaos Warrior
Set GRealMaxSize[2] = 3
Set GCurrentMaxSize[2] = 3
Set GUpgradeItem01[2] = Chaos Chosen Warrior
Set GMoraleDamageAmount[2] = 20
-------- Chaos Warhounds --------
Set GLeaderIsDifferent[3] = False
Set GLeaderUnitType[3] = Chaos Warhound
Set GRealMaxSize[3] = 4
Set GCurrentMaxSize[3] = 4
Set GUpgradeItem01[3] = (Item-type of No item)
Set GMoraleDamageAmount[3] = 1

My problem is that the indexes are tied to the point values of the units (and obviously I don't want to do this as I want it to be lightweight and customizable for future upload here at THW). How can I get around using the point value? I need an integer value to be tied to each unit type, is this possible with hashtables perhaps? To clarify what I use the point value for, when a unit is trained, takes damages, loses members, etc the relevant data is assessed using this table and the point value is tied to the associated table data through its index.
 
Level 11
Joined
Jun 2, 2004
Messages
849
Yeah hashtables would suit your needs perfectly. I don't feel like writing up my own explanation of them so I'll just link to the first tutorial I found:

A Complete Beginners Guide to Hashtables



Instead of using point values, you can use the unit type directly (it's an integer after all) to index your hashtable. This is awkward in GUI though so even when not using jass directly I pretty much always put hashtable functions in custom text.
 
Level 22
Joined
Jul 25, 2009
Messages
3,091
I hate to sound stupid but that tutorial doesn't exactly do a good job of explaining to me what I'm trying to learn. How do I save my unit type to my integer and then reference it through an event like "Unit finished Training."
 
Level 11
Joined
Jun 2, 2004
Messages
849
Code:
    local integer UnitType = GetUnitTypeId(GetTrainedUnit())
    set udg_TempInt = LoadIntegerBJ(0, UnitType, udg_MyHashTable)
    call SaveIntegerBJ(udg_TempInt, 0, UnitType, udg_MyHashTable)
First line gets the unit type of the trained unit.
Second line loads an integer from MyHashTable, indexed by UnitType, second index being 0 (hashtables are two dimensional; 0 just gets the first element), and stores it to a global TempInt. LoadInteger may be better than LoadIntegerBJ; I was lazy and just converted to custom text from the GUI function.
Third line saves an integer to the hashtable. First index is again UnitType. Second index is again 0, just as an arbitrary value. udg_TempInt is the argument being saved.

Done in JASS because as far as I could tell you can't use unit types in GUI for indexing. Hashtables are not well implemented in GUI.
 
Status
Not open for further replies.
Top