• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[Solved] "Hashtable - Save Integer" not doing anything

Status
Not open for further replies.
Level 4
Joined
Oct 2, 2015
Messages
74
Just as the title says.
I have a trigger that uses the "Hashtable - Save Integer" function to assign the integer value of 1 to 0 of key of triggering unit.
Yet when i load it in another trigger, the value is 0.
I have checked the keys too, and it's the same unit.
What have i done wrong?
 
Just as the title says.
I have a trigger that uses the "Hashtable - Save Integer" function to assign the integer value of 1 to 0 of key of triggering unit.
Yet when i load it in another trigger, the value is 0.
I have checked the keys too, and it's the same unit.
What have i done wrong?
I'd guess that you have not created the hashtable. It's a classic on for me at least.

But other than that, you'll have to post a trigger for use to say anything...
 
Level 4
Joined
Oct 2, 2015
Messages
74
Here are my triggers

This is the one that saves 1 as 0 of key of triggering unit, and the problem has nothing to do with the condition, i have checked and it's working correctly.
  • Factory Production Hashtable
    • Events
      • Unit - A unit Is issued an order with no target
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Issued order) Equal to (Order(carrionscarabson))
        • Then - Actions
          • Hashtable - Save 1 as 0 of (Key (Triggering unit)) in FactoryProduction
        • Else - Actions
This is the trigger that is using the same value of 0 of the same key, i have checked that as well and confirmed that it was the same 0 of the same key, yet the value was 0 despite the trigger that should have assigned 1 to it.
  • Factory Atomic
    • Events
      • Unit - A unit Finishes research
    • Conditions
      • (Researched tech-type) Equal to Neolithic Era
      • (Current research level of Neolithic Era for (Owner of (Triggering unit))) Equal to 14
    • Actions
      • Unit Group - Pick every unit in (Units owned by (Owner of (Triggering unit)) matching ((Unit-type of (Matching unit)) Equal to Factory (Industrial))) and do (Actions)
        • Loop - Actions
          • Unit - Replace (Picked unit) with a Factory (Atomic) using The old unit's life and mana
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Load 0 of (Key (Last replaced unit)) from FactoryProduction) Equal to 1
            • Then - Actions
              • Unit - Order (Last replaced unit) to Undead Crypt Lord - Activate Carrion Beetles
            • Else - Actions
 

Uncle

Warcraft Moderator
Level 65
Joined
Aug 10, 2018
Messages
6,657
You're loading the key of the last replaced unit which an entirely different unit than the picked unit.
The Replace action removes the original unit and creates a new unit in it's place.

What you need to do is Load the key of the picked unit into an Integer variable, then replace the unit, and finally check the loaded value:
  • Set Variable LoadedInt = (Load 0 of (Key (Picked unit)) from FactoryProduction
  • Unit - Replace (Picked unit) with a Factory (Atomic) using The old unit's life and mana
  • If (LoadedInt Equal to 1) then Order (Last replaced unit) to Undead Crypt Lord - Activate Carrion Beetles

You may also want to clear the Child hashtables of your Picked unit right after setting LoadedInt.
  • Set Variable LoadedInt = (Load 0 of (Key (Picked unit)) from FactoryProduction
  • Hashtable - Clear all child hashtables of (Key(Picked unit)) from FactoryProduction
This will clear the data (which is no longer needed) and help keep things running efficiently.

Last thing, this leaks a Unit Group:
  • Unit Group - Pick every unit in (Units owned by (Owner of (Triggering unit)) matching ((Unit-type of (Matching unit)) Equal to Factory (Industrial))) and do (Actions)
 
Last edited:
Level 4
Joined
Oct 2, 2015
Messages
74
You're loading the key of the last replaced unit which an entirely different unit than the picked unit.
The Replace action removes the original unit and creates a new unit in it's place.

What you need to do is Load the key of the picked unit into an Integer variable, then replace the unit, and finally check the loaded value:
  • Set Variable LoadedInt = (Load 0 of (Key (Picked unit)) from FactoryProduction
  • Unit - Replace (Picked unit) with a Factory (Atomic) using The old unit's life and mana
  • If (LoadedInt Equal to 1) then Order (Last replaced unit) to Undead Crypt Lord - Activate Carrion Beetles

You may also want to clear the Child hashtables of your Picked unit right after setting LoadedInt.
  • Set Variable LoadedInt = (Load 0 of (Key (Picked unit)) from FactoryProduction
  • Hashtable - Clear all child hashtables of (Key(Picked unit)) from FactoryProduction
This will clear the data (which is no longer needed) and help keep things running efficiently.

Last thing, this leaks a Unit Group:
  • Unit Group - Pick every unit in (Units owned by (Owner of (Triggering unit)) matching ((Unit-type of (Matching unit)) Equal to Factory (Industrial))) and do (Actions)
ok so i've tried this:

  • Factory Atomic
    • Events
      • Unit - A unit Finishes research
    • Conditions
      • (Researched tech-type) Equal to Neolithic Era
      • (Current research level of Neolithic Era for (Owner of (Triggering unit))) Equal to 14
    • Actions
      • Unit Group - Pick every unit in (Units owned by (Owner of (Triggering unit)) matching ((Unit-type of (Matching unit)) Equal to Factory (Industrial))) and do (Actions)
        • Loop - Actions
          • Set LoadedInt = (Load 0 of (Key (Picked unit)) from FactoryProduction)
          • Game - Display to (All players) the text: (String(LoadedInt))
          • Game - Display to (All players) the text: (String((Key (Picked unit))))
          • Unit - Replace (Picked unit) with a Factory (Atomic) using The old unit's life and mana
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • LoadedInt Equal to 1
            • Then - Actions
              • Unit - Order (Last replaced unit) to Undead Crypt Lord - Activate Carrion Beetles
              • Game - Display to (All players) the text: It's working
            • Else - Actions
but it still didn't work.
i've added the display messages to track the issue, and apparently, the value is 0 even before the unit is replaced.
is there something i am missing?

EDIT: this may have to do with the fact that the unit is also upgraded with an ability based on the berserker upgrade at the same moment the trigger fires (neolithic era level 14 is researched), but i am not sure about how likely it is since the unit does get replaced.
but assuming the berserker upgrade is an issue, is there a way to make it not reset the unit's mana, which is the reason i am doing all of those triggers in the first place?
 

Uncle

Warcraft Moderator
Level 65
Joined
Aug 10, 2018
Messages
6,657
It must be an issue with Berserk or something similar. It's not the same unit that it was when you initially Saved the value to it.

Anyway, why not store the current mana of your unit in a variable before changing it, and then set the new unit's mana to this value?
 
Level 4
Joined
Oct 2, 2015
Messages
74
It must be an issue with Berserk or something similar. It's not the same unit that it was when you initially Saved the value to it.

Anyway, why not store the current mana of your unit in a variable before changing it, and then set the new unit's mana to this value?
shouldn't that give me the same issue? or is there a way to detect when a unit is just about to be upgraded?
 

Uncle

Warcraft Moderator
Level 65
Joined
Aug 10, 2018
Messages
6,657
Can't you get the unit before it changes? Surely there's a way.

I guess it's a bit tricky... hmm.

One idea that comes to mind is to use an additional Upgrade which acts as the requirement to the Berserk ability, and then Research it in response to the first Upgrade finishing. This way you can get the units before they upgrade. Now the trick is to store their mana in a way that you can properly use it after the second research finishes and Berserk has kicked in.

So like:
1: The first research finishes.
2: The Event goes off for "A unit finishes research".
3: You Pick every unit and store their mana values in an Array.
4: You research the REAL upgrade which activates the Berserk ability.
5: Wait until the units have changed, which may actually be instantaneous.
6: Pick every changed unit and iterate over the Mana Array, applying the mana to the unit.

This will only work if the Pick Every Unit function picks the units in the same exact order as it did before. I've seen it behave this way before so maybe it'll work.
 
Last edited:
Level 20
Joined
Apr 12, 2018
Messages
494
Okay I mostly recreated your triggers (based on Post #6 version) in my test map (barring the research action/condition because I don't think that has anything to do with anything and I don't have time for that) and the conclusion I came to is I only saw your behavior when I DID NOT create a Hashtable first. It actually worked the way it was supposed to when I made the Hashtable at Map Initialization.

  • Melee Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set Table = (Last created hashtable)
  • Trigger1
    • Events
      • Unit - A unit Is issued an order with no target
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Issued order) Equal to (Order(carrionscarabson))
        • Then - Actions
          • Hashtable - Save 1 as 0 of (Key (Triggering unit)) in Table
          • Game - Display to (All players) for 5.00 seconds the text: 1 Stored!
        • Else - Actions
Here is the major differences where I'm replacing Altar of Kings with Barracks, where Altar of Kings has the Carrion Beetles ability.

  • Trigger2
    • Events
      • Player - Player 1 (Red) Presses the Down Arrow key
    • Conditions
    • Actions
      • Trigger - Turn off Trigger1 <gen>
      • Unit Group - Pick every unit in (Units owned by Player 1 (Red) matching ((Unit-type of (Matching unit)) Equal to Altar of Kings)) and do (Actions)
        • Loop - Actions
          • Set TempInt = (Load 0 of (Key (Picked unit)) from Table)
          • Game - Display to (All players) for 5.00 seconds the text: ((String((Unit-type of (Picked unit)))) + (String(TempInt)))
          • Unit - Replace (Picked unit) with a Barracks using The old unit's relative life and mana
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • TempInt Equal to 1
            • Then - Actions
              • Unit - Add Carrion Beetles to (Last replaced unit)
              • Unit - Order (Last replaced unit) to Undead Crypt Lord - Activate Carrion Beetles
              • Hashtable - Save 1 as 0 of (Key (Last replaced unit)) in Table
            • Else - Actions
      • Trigger - Turn on Trigger1 <gen>
I don't think I deviated from the spirit of your triggers any, but that's the conclusion I came up with.

I am making a massive assumption that there is nothing that can otherwise alter the Hastable value.
 
Last edited:
Level 4
Joined
Oct 2, 2015
Messages
74
Okay I mostly recreated your triggers (based on Post #6 version) in my test map (barring the research action/condition because I don't think that has anything to do with anything and I don't have time for that) and the conclusion I came to is I only saw your behavior when I DID NOT create a Hashtable first. It actually worked the way it was supposed to when I made the Hashtable at Map Initialization.

  • Melee Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set Table = (Last created hashtable)
  • Trigger1
    • Events
      • Unit - A unit Is issued an order with no target
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Issued order) Equal to (Order(carrionscarabson))
        • Then - Actions
          • Hashtable - Save 1 as 0 of (Key (Triggering unit)) in Table
          • Game - Display to (All players) for 5.00 seconds the text: 1 Stored!
        • Else - Actions
Here is the major differences where I'm replacing Altar of Kings with Barracks, where Altar of Kings has the Carrion Beetles ability.

  • Trigger2
    • Events
      • Player - Player 1 (Red) Presses the Down Arrow key
    • Conditions
    • Actions
      • Trigger - Turn off Trigger1 <gen>
      • Unit Group - Pick every unit in (Units owned by Player 1 (Red) matching ((Unit-type of (Matching unit)) Equal to Altar of Kings)) and do (Actions)
        • Loop - Actions
          • Set TempInt = (Load 0 of (Key (Picked unit)) from Table)
          • Game - Display to (All players) for 5.00 seconds the text: ((String((Unit-type of (Picked unit)))) + (String(TempInt)))
          • Unit - Replace (Picked unit) with a Barracks using The old unit's relative life and mana
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • TempInt Equal to 1
            • Then - Actions
              • Unit - Add Carrion Beetles to (Last replaced unit)
              • Unit - Order (Last replaced unit) to Undead Crypt Lord - Activate Carrion Beetles
              • Hashtable - Save 1 as 0 of (Key (Last replaced unit)) in Table
            • Else - Actions
      • Trigger - Turn on Trigger1 <gen>
I don't think I deviated from the spirit of your triggers any, but that's the conclusion I came up with.

I am making a massive assumption that there is nothing that can otherwise alter the Hastable value.
well damn i was stupid... i assumed that creating the variable creates the hashtable automatically, but now everything is clear.
it works now.
 
Level 20
Joined
Apr 12, 2018
Messages
494
Yeah that's just a quirk of the Hashtable since it was added much later in Warcraft 3's life that it wasn't set up so it's initialized for you. I only tested for that based on Post #3 suggesting that may be the case.
 
Status
Not open for further replies.
Top