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

Help with hashtables and handles

Status
Not open for further replies.
Level 8
Joined
Jul 29, 2010
Messages
319
So i'm running into a very strange issue, this trigger does what it's supposed to do except instead of the floating text action placing numbers 1, 2 ,3 ,4 etc above units heads, it instead gives the numbers 1048587, 1048589, 1048590, 1048591 and so on, always starting from 1048587. o_O what is going on?
  • Allocating Variables
    • Events
      • Time - TempTimer expires
    • Conditions
    • Actions
      • -------- x[1] is used for players, x[2] is used for units --------
      • Set x[1] = 0
      • For each (Integer A) from 1 to 8, do (Actions)
        • Loop - Actions
          • Set x[1] = (x[1] + 1)
          • Set x[2] = 0
          • Unit Group - Pick every unit in (Units owned by (Player(x[1]))) and do (Actions)
            • Loop - Actions
              • Unit Group - Add (Picked unit) to PlayersUnits
              • Set TempUnitVariable = (Random unit from PlayersUnits)
              • For each (Integer B) from 1 to (Number of units in PlayersUnits), do (Actions)
                • Loop - Actions
                  • Set x[2] = (x[2] + 1)
                  • Hashtable - Save Handle OfTempUnitVariable as x[2] of 1 in PlayerUnits
                  • Unit Group - Remove TempUnitVariable from PlayersUnits
                  • Floating Text - Create floating text that reads (String((Key (Load x[2] of 1 in PlayerUnits)))) above TempUnitVariable with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
                  • Set TempUnitVariable = No unit
 
It prints the handle id of the unit (Course 4, HandleId), not the x[2] index. But I believe what you want to do is this:

  • For each (Integer i) from 1 to 8, do (Actions)
    • Loop - Actions
      • Set k = 0
      • Set group = (Units owned by (Player(i)))
      • Unit Group - Pick every unit in group and do (Actions)
        • Loop - Actions
          • Set u = (Picked unit)
          • Hashtable - Save Handle Ofu as k of i in hash
          • Floating Text - Create floating text that reads (String(k)) above u with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
      • Custom script: call DestroyGroup(udg_group)
Being note there is a floating text limit of maximum 100 floating texts at same time.
 
Level 8
Joined
Jul 29, 2010
Messages
319
It prints the handle id of the unit (Course 4, HandleId), not the x[2] index. But I believe what you want to do is this:

  • For each (Integer i) from 1 to 8, do (Actions)
    • Loop - Actions
      • Set k = 0
      • Set group = (Units owned by (Player(i)))
      • Unit Group - Pick every unit in group and do (Actions)
        • Loop - Actions
          • Set u = (Picked unit)
          • Hashtable - Save Handle Ofu as k of i in hash
          • Floating Text - Create floating text that reads (String(k)) above u with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
      • Custom script: call DestroyGroup(udg_group)
Being note there is a floating text limit of maximum 100 floating texts at same time.
Thank you, I need a way of grabbing a unit's HandleID whenever a trigger needs it, i need a system that will save handle ID's in order of each units Custom Value, another problem i encountered was that i can't seem to change a units custom value for some reason.
An example being this trigger
  • Health Matrix
    • Events
      • Time - Elapsed game time is 1.00 seconds
    • Conditions
    • Actions
      • Set Y = 1
      • Set Z = 1
      • For each (Integer A) from 1 to ActivePlayerUnits, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Max HP of Alpha[Y]) Greater than (Max HP of Alpha[Z])
            • Then - Actions
              • Set Y = (Y + 1)
              • Set Z = 1
              • -------- Amount Of "Priority" Added to unit --------
              • Set CustomValue = (CustomValue + 1)
              • Unit - Set the custom value of Alpha[Y] to ((Custom value of Alpha[Y]) + 10)
              • Game - Display to (All players) the text: (String((Custom value of Alpha[Y])))
            • Else - Actions
              • Set Z = (Z + 1)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Z Greater than or equal to ActivePlayerUnits
                • Then - Actions
                  • Set Z = 1
                  • Set Y = (Y + 1)
                • Else - Actions
I can't figure out why it won't change the Custom value, using the Display text action it always tell me that the units custom value is 0
 
Do you use a unit indexer? If not it's probably recommended, because it will automatically assign unique custom values for all units that will exist.

Once a trigger can refer to a unit, then you automatically can get its HandleId, and also its custom value (which should come from UnitIndexer), so I'm not very sure it makes much sense to attach the handle id to the custom value - they have basically the same goal.

Key(<Unit>) in GUI is the HandleId == GetHandleId(<Unit>) in JASS

==

The loop, I'm not very sure of how values are computed, or if it all is really what is wanted, sorry. I would need some more details, like what is the exact goal?
 
Level 8
Joined
Jul 29, 2010
Messages
319
Do you use a unit indexer? If not it's probably recommended, because it will automatically assign unique custom values for all units that will exist.

Once a trigger can refer to a unit, then you automatically can get its HandleId, and also its custom value (which should come from UnitIndexer), so I'm not very sure it makes much sense to attach the handle id to the custom value - they have basically the same goal.

Key(<Unit>) in GUI is the HandleId == GetHandleId(<Unit>) in JASS

==

The loop, I'm not very sure of how values are computed, or if it all is really what is wanted, sorry. I would need some more details, like what is the exact goal?
The overall goal is a system that will actively increase a units custom value based on it's health, movement speed, attack damage and amour, as the those 4 values increase due to ingame upgrades that you obtain as you play through each wave, the custom value increases as well, this which ever unit that has the highest custom value will be the main target of the "monsters" each wave, as the overall custom values of each unit increase, so does the strength of the units that are being spawned.
 
I would import a indexer system, for example GUI Unit Indexer 1.4.0.0, and then all units have unique custom values by default - they should be untouched (meaning only be read).

Then a new integer[array] variable, example UnitPower[], can be created which will define a unit's current power defined by the four criteria.

Like then we can define it like:

set index = CustomValue(myUnit)
UnitPower[index] = HealthOf(myUnit) + ... ( )

for the unit with the highest UnitPower there can be an extra integer variable that can be re-assigned, so we expand:

set index = CustomValue(myUnit)
UnitPower[index] = HealthOf(myUnit) + ... ( )
..
If UnitPower[index] GREATER THAN UnitPower[MaxUnitPowerIndex] then
---- MaxUnitPowerIndex = index
Endif

// meaning the unit with custom value MaxInitPowerIndex is always the strongest unit.
 
Status
Not open for further replies.
Top