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

[Hashtable] Saving an integer with an unit-type

Status
Not open for further replies.

Ardenian

A

Ardenian

Hello,

just playing a bit around with hashtables, so I would like to receive some help:

I would like to save multiple ( = unlimited) unit-types in the hashtable and save one integer for every unit-type saved in the hashtable.

Could someone provide me a short example of the save and if possible of a load, too, please ?
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
Not with GUI only.
What you can do is use GetUnitTypeId() to save the unit type id in a global unit-type variable and using a custom script to copy the value to a global integer variable.
  • Actions
    • Hashtable - Create a hashtable
    • Set RegistryTable = (Last created hashtable)
    • -------- - --------
    • -------- - --------
    • -------- - --------
    • Set TempUnitType[0] = Peasant
    • Custom script: set udg_TempInteger[0] = udg_TempUnitType[0]
    • Hashtable - Save 123 as 0 of TempInteger[0] in RegistryTable
    • -------- - --------
    • Set TempUnitType[0] = Footman
    • Custom script: set udg_TempInteger[0] = udg_TempUnitType[0]
    • Hashtable - Save 123 as 0 of TempInteger[0] in RegistryTable
    • -------- - --------
    • Set TempUnitType[0] = Knight
    • Custom script: set udg_TempInteger[0] = udg_TempUnitType[0]
    • Hashtable - Save 123 as 0 of TempInteger[0] in RegistryTable
    • -------- - --------
    • Set TempUnitType[0] = Rifleman
    • Custom script: set udg_TempInteger[0] = udg_TempUnitType[0]
    • Hashtable - Save 123 as 0 of TempInteger[0] in RegistryTable
    • -------- - --------
    • Set TempUnitType[0] = Mortar Team
    • Custom script: set udg_TempInteger[0] = udg_TempUnitType[0]
    • Hashtable - Save 123 as 0 of TempInteger[0] in RegistryTable
This means that TempInteger[0] will be the same as TempUnitType[0].
(TempInteger is a global variable of type Integer and is an array.
TempUnitType is a global variable of type Unit-Type and is an array.)

You should be able to do the loading from the hashtable yourself if you understand this.
 

Ardenian

A

Ardenian

Thank you!
Hm, I am not sure whether I explained it well/ whether this is what I am searching for.

So, we have a unit type 'Peasent'.
The integer I would like to save with the unit-type 'Peasent' is '123' then, after yours ?

So, a load would look like:
  • Custom script: set udg_TempUnitType[0]= GetUnitTypeId( udg_IndexedUnit[udg_LoopInteger])
  • Set TempUnitType[0] = (Load 0 of TempInteger[0] from RegistryTable)
Now TempUnitType[0] = 123 ?

I don't have to set the array of TempInteger[0] to something else, have I ?
Just let them as they are in your example ?
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
Not really, you have to set the TempUnitType to the unit type you want.
Then you use the custom script like I showed you to make TempUnit have that id as well.
The first two lines of that trigger that I showed you will continually return in these cases.

In the third line, I stored 123 as the value stored under "0" and the unit type.
So you set TempInteger to load integer from hashtable "Set TempInteger[1] = (Load 0 of TempInteger[0] from RegistryTable)"
(TempInteger[1] is not 123.)
 

Ardenian

A

Ardenian

That means:
  • Custom script: set udg_TempUnitType[0]= GetUnitTypeId( udg_IndexedUnit[udg_LoopInteger])
  • Custom script: set udg_TempInteger[0] = udg_TempUnitType[0]
  • Set TempInteger[1] = (Load 0 of TempInteger[0] from RegistryTable)
So, now TempInteger[1] = 123, as far as I understand this.
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
Kind of...it would work but you can still do the first line using GUI:
  • Set TempUnitType[0] = (Unit-type of IndexedUnit[LoopInteger])
  • Custom script: set udg_TempInteger[0] = udg_TempUnitType[0]
  • Set TempInteger[1] = (Load 0 of TempInteger[0] from RegistryTable)]
Just something that could just be easier to use and will give you less probability of making mistakes.
 
Status
Not open for further replies.
Top