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

Saving a unit-type to a hashtable?

Status
Not open for further replies.
Level 19
Joined
Aug 16, 2007
Messages
881
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.
 
Level 19
Joined
Aug 16, 2007
Messages
881
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 12
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 12
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)
 
Level 19
Joined
Aug 16, 2007
Messages
881
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?
 
Level 19
Joined
Aug 16, 2007
Messages
881
The "HeroList" is actually an unit type variabel, but the thing is, if I only leave the herolist there, I won't be able to save the unit type into a hashtable? I someway thought Pharaoh_s' script converted the unit type into either a unit variabel or an integer (and those variables can be saved into a hashtable).
 
Level 19
Joined
Aug 16, 2007
Messages
881
Oh, now I understand! :D Thanks you, now I'll be able to continue on the thing I was working at. Just one last question

JASS:
// IF I GOT IT RIGHT I CAN EITHER USE AN INTEGER OR A UNIT-TYPE VARIABEL @ x, RIGHT?
call AddUnitToStockBJ( x, gg_unit_n00V_0115, 1, 1 )

(I'll just have to be sure...)

Anyway, +rep for you :)
 
Status
Not open for further replies.
Top