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

[Hashtables] unit type as handle

Status
Not open for further replies.
Level 25
Joined
Jul 10, 2006
Messages
3,315
I'm trying to replace this little gem:
  • UFS Add Unit
    • Events
      • Game - UnitIndexEvent becomes Equal to 1.00
    • Conditions
      • (UDexUnits[UDex] is A Hero) Equal to False
    • Actions
      • For each (Integer B) from 1 to ufsVAR_unitId, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of UDexUnits[UDex]) Equal to ufsVAR_unitType[(Integer B)]
            • Then - Actions
              • Unit - Add ufsVAR_FuseAbility to UDexUnits[UDex]
            • Else - Actions
with a hashtable check.

First time using hashtables, I've read the beginner tutorial twice over, as well as the other one.

Is there a way to save a unit type as a handle? Because I can't find it.

I tried Conversion - Convert unit-type to order, but this didn't compile.
I tried a string ID (converting unit type to string), which loads no data.

Can hashtables not actually handle (excuse the pun) unit types? Or do I need to go back to the tutorial and add more patience?
 
Well, this is the ugly face of GUI. Create a variable called TempInt that is an integer, and a TempUnit variable that is an unit. Set TempUnit = whatever you need to, then use this as custom script:
JASS:
set udg_TempInt = GetUnitTypeId(udg_TempUnit)
After that, use TempInt as your 'key' in a hashtable. It means, that if your unit type id is 'hpea' it will be 'hpea'. GUI is ugly about this since it does not recognize unit type as an integer, which it really is, unit type is NOT a handle.
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
Well, this is the ugly face of GUI. Create a variable called TempInt that is an integer, and a TempUnit variable that is an unit. Set TempUnit = whatever you need to, then use this as custom script:
JASS:
set udg_TempInt = GetUnitTypeId(udg_TempUnit)
After that, use TempInt as your 'key' in a hashtable. It means, that if your unit type id is 'hpea' it will be 'hpea'. GUI is ugly about this since it does not recognize unit type as an integer, which it really is, unit type is NOT a handle.

Too bad he want to save values to a Unit-type, not Unit.

This is how you do it;.
  • Set UnitType = Medivh
  • Custom script: set udg_TempInteger = udg_UnitType
  • Hashtable - Save 100 as 0 of TempInteger in YourHashtable
This trigger will save value of 100 to a Unit-type named Medivh.

To load it;
  • Set TempUnit = (Triggering unit) or any other event-response
  • Custom script: udg_TempInteger = GetUnitTypeId(udg_TempUnit)
  • Custom script: call BJDebugMsg(I2S(udg_TempInteger))
This trigger will show '100' on your screen, loaded from a unit caused by a Unit-type.

See what I did there ?

Compared to HappyTauren's, he's saving data to a UNIT whether you should be saving data to a UNIT-TYPE

I did this method a lot in my system, you can check them (Spell Power / Income Generator / Item Durability), you can take a look at the Setup Trigger and learn something from it.
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
You're right, he isn't firing an event that returns a unit, so what you've thought of is what he should do.

Is there a way to save a unit type as a handle? Because I can't find it.
Perhaps his trigger is wrong in some cases ?
He wants to show that he want to save a value to a unit-type, I just interpret it by his words, while you interpret it by his trigger.

I believe words more than trigger.

Also,
GUI is ugly about this since it does not recognize unit type as an integer, which it really is, unit type is NOT a handle.

  • Set UnitType = Medivh
  • Custom script: set udg_TempInteger = udg_UnitType
  • Hashtable - Save 100 as 0 of TempInteger in YourHashtable

I may be wrong, the situation is vague for me, I'll wait for him to come here and explain what he really want to do.
 
Level 25
Joined
Jul 10, 2006
Messages
3,315
So I can't actually directly save the unit type?

With this method, I'll have to preload one of every unit type at map startup.

Well, at least it works.

Thanks guys

EDIT:
  • Set UnitType = Medivh
  • Custom script: set udg_TempInteger = udg_UnitType
  • Hashtable - Save 100 as 0 of TempInteger in YourHashtable
If this is legit, AAAAAAAW YEAH
 
Last edited:
Status
Not open for further replies.
Top