• 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.

Saving a unit-type to a hashtable?

Status
Not open for further replies.
Hello, I'm wondering if I'm able to save an unit-type to a hashtable? I can't find an action for that. The closest thing I can come up with is this:
  • Hashtable - Save Handle Of(Random unit from (Units of type GM_tCH_HeroList[Integer[0]])) as ForLoopInteger[1] of i in GM_tCH_Hashtable
but it isn't working (and yes, I know that all variables are correct).

Thanks.
 
Save the unit first, and then retrieve its unit-type as follows:
  • Hashtable - Save Handle of (yourunit) as (Key(unit)) of (Key(your key)) in GM_tCH_Hashtable
  • Unit - Create 1 (Unit-type of (Load (Key(unit)) of (Key(your unit)) in GM_tCH_Hashtable) for (Owner of (Triggering unit)) at Point1 facing default building degrees

Yes, I know I can do it in that way, but the thing is: I don't want to create a new unit all the time to store it. I've pre-set all the unit types into an Unit-Type variable and I want to set those unit types into a hashtable.

I can show you the whole trigger.

  • PreCreate Heroes for a Player
    • Events
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set GM_tCH_Hashtable = (Last created hashtable)
      • -------- -------------------------------- --------
      • For each (Integer ForLoopInteger[20]) from 1 to MaxHeroes, do (Actions)
        • Loop - Actions
          • Set GM_tCH_HeroList[ForLoopInteger[20]] = RandomHero[ForLoopInteger[20]]
      • -------- -------------------------------- --------
      • For each (Integer ForLoopInteger[0]) from 1 to 12, do (Actions)
        • Loop - Actions
          • Set p = (Player(ForLoopInteger[0]))
          • Set i = ForLoopInteger[0]
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • And - All (Conditions) are true
                • Conditions
                  • i Not equal to 6
                  • i Not equal to 12
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (p controller) Equal to User
                  • (p slot status) Equal to Is playing
                • Then - Actions
                  • For each (Integer ForLoopInteger[1]) from 1 to 4, do (Actions)
                    • Loop - Actions
                      • Set Integer[0] = (Random integer number between 1 and MaxHeroes)
                      • Hashtable - Save Handle Of(Random unit from (Units of type GM_tCH_HeroList[Integer[0]])) as ForLoopInteger[1] of i in GM_tCH_Hashtable
                      • Game - Display to (All players) the text: (Name of (Load ForLoopInteger[1] of i in GM_tCH_Hashtable))
                • Else - Actions
            • Else - Actions
 
Level 13
Joined
Apr 15, 2008
Messages
1,063
No actually you can't. Unit-type is in fact an integer, only in GUI it's a separate variable type (same for ability and item type, however for ability there is a function). The only solution here would be to use JASS version of the function for this purpose.

EDIT: I really don't get the GUI functions for hashtable, there are types like triggercondition, triggeraction, trackable, which you can't even use in GUI, but unit-type is not there. Also, there is "EventId" function, which actually crashes WE when you click the eventid field :grin:

EDIT 2: maybe it's just me, but WE crashes also on unitpool, multiboarditem, trackable and itempool.
 
Yep, try something like this:
  • Custom script: set udg_UnitType = (GetUnitTypeId(udg_RandomHero[udg_ForLoopInteger[20]]))
  • Hashtable - Save UnitType as (Key(X)) of (Key(Y)) in Hashtable
  • Set LoadUnit = (Load (Key(X)) of (Key(Y)) in Hashtable
  • Custom script: call CreateUnit (GetOwningPlayer(X), udg_LoadUnit, x, y, 270)
M0RT, those functions were never implemented in GUI.
 
Level 13
Joined
Apr 15, 2008
Messages
1,063
That is not true, they are implemented in GUI, they have their JASS versions in blizzard.j, it is the variable types that are not implemented. When the dialog for respective variable type should appear, it instead crashes WE.

Also, another major failure of Hashtables are abilities. There is a special type, "ability", that has only two uses: LoadAbility and SaveAbility. (yeah, it can't be even created) Ofc WE crashes when on this type. (everywhere else abilities are identified with integers, just for hashtables there is some special variable type)
 
Yep, try something like this:
  • Custom script: set udg_UnitType = (GetUnitTypeId(udg_RandomHero[udg_ForLoopInteger[20]]))
  • Hashtable - Save UnitType as (Key(X)) of (Key(Y)) in Hashtable
  • Set LoadUnit = (Load (Key(X)) of (Key(Y)) in Hashtable
  • Custom script: call CreateUnit (GetOwningPlayer(X), udg_LoadUnit, x, y, 270)
M0RT, those functions were never implemented in GUI.

I'll try it out when I've got time :) Thanks, +rep (Can't rep you yet)



EDIT: I've tried your script but it doesn't work...

Script:
  • Custom script: set udg_UnitType = (GetUnitTypeId(udg_GM_tCH_HeroList[udg_Integer[0]]))
Error: Line 5354: Invalid argument type (integer)

I've tried to get it to working, but it doesn't. What do you think?
 
Status
Not open for further replies.
Top