• 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.
  • It's time for the first HD Modeling Contest of 2025. Join the theme discussion for Hive's HD Modeling Contest #7! Click here to post your idea!

[Trigger] Issue with trade system hashtable

Level 9
Joined
Dec 1, 2010
Messages
346
For my trade system, i've started tackling the final part, the loading and unloading of goods into a trade node. For this, i make heavy use of two hashtables also used in my other triggers.

This part of the system should check if a transport ship is in proximitty, then from it's hashtable look for the number transported and the integer of the good transported. Based on that it will check if in the node where the [tradeport] is build there's sufficient resources of the corresponding type, and then deduct those from that node. After deduction, an item corresponding to the resource is added to the ship, and the amount of stacks is set to the 'transportted amount' integer (1-9) from the hashtable.

All of this worked, however when i have two ships, i've noticed that it will take the transported amount of one of the ships for both. dropping off is function correctly but picking up will consistently give this problem when running a trade line with multiple ships.

I've added the map as an attachment Since this is the very last part of a multi trigger system. and testing purposes.

I feel like my issue is with the hashtable setting or sometthing but i can't seem to figure out where this is.


Hashtable [3`]

Slot 0 = Unit ID
Slot 1 = handle of homeport
Slot 2 = Handle of target tradepoint
Slot 3 = Current order integer (0 = No order, 1 = Deliver cargo to target, 2 = Return to homeport)
slot 4 = Player number [owner]
slot 5 = amount transported
slot 6 = tradegood number= (1=wood,2=stone,3=food,...))



Hashtable [1`]

Slot1 = ID
Slott2: Unit type
Slot 3 = Tradenode number
slot 4 = Gold cost
slot 5 = wood cost
slot 6 =





  • unload Homeport
    • Events
      • Time - Every 0.50 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in tradePorts and do (Actions)
        • Loop - Actions
          • Set VariableSet portPos = (Position of (Picked unit))
          • Set VariableSet tempUnit = (Picked unit)
          • Unit Group - Pick every unit in (Units within 300.00 of portPos matching ((Unit-type of (Matching unit)) Equal to Transport Ship).) and do (Actions)
            • Loop - Actions
              • -------- If tradeship and going to homeport and port in range is homeportt --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Load 3 of (Key (Picked unit).) from hashtable[3].) Equal to 2
                  • (Load 1 of (Key (Picked unit).) in hashtable[3].) Equal to tempUnit
                • Then - Actions
                  • Game - Display to (All players) the text: Reached homeport pi...
                  • -------- Check if tradegood is in stock --------
                  • -------- wood --------
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Load 6 of (Key (Picked unit).) from hashtable[3].) Equal to 1
                      • (Load 5 of (Key (Matching unit).) from hashtable[3].) Less than or equal to wood[(Load 3 of (Key (Load 1 of (Key (Picked unit).) in hashtable[3].).) from hashtable[1].)]
                    • Then - Actions
                      • -------- If wood in stock > needed wood for transport --------
                      • -------- Set wood to new value --------
                      • Set VariableSet wood[(Load 3 of (Key (Load 1 of (Key (Picked unit).) in hashtable[3].).) from hashtable[1].)] = (wood[(Load 3 of (Key (Load 1 of (Key (Picked unit).) in hashtable[3].).) from hashtable[1].)] - (Load 5 of (Key (Matching unit).) from hashtable[3].))
                      • -------- Add item --------
                      • Hero - Create wood and give it to (Picked unit)
                      • Item - Set charges remaining in (Last created item) to (Load 5 of (Key (Matching unit).) from hashtable[3].
                      • Hashtable - Save 1 as 3 of (Key (Picked unit).) in hashtable[3].
                    • Else - Actions
                      • -------- Not enough wood in node --------
                      • Game - Display to (All players) the text: Not sufficient of s...
                  • -------- stone --------
                  • -------- food --------
                • Else - Actions
              • -------- If tradeship and going to destination port and port in range is destination port --------
              • Game - Display to (All players) the text: (String((Load 3 of (Key (Picked unit).) from hashtable[3].)))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Load 3 of (Key (Picked unit).) from hashtable[3].) Equal to 1
                  • (Load 2 of (Key (Picked unit).) in hashtable[3].) Equal to tempUnit
                • Then - Actions
                  • Game - Display to (All players) the text: Reached Destination...
                  • Hashtable - Save 0 as 3 of (Key (Picked unit).) in hashtable[3].
                  • Item - Create (Item-type of (Item carried by (Picked unit) in slot 1)) at (Center of (Playable map area))
                  • Item - Set charges remaining in (Last created item) to (Charges remaining in (Item carried by (Picked unit) in slot 1))
                  • Hero - Give (Last created item) to tempUnit
                  • Item - Remove (Item carried by (Picked unit) in slot 1)
                  • Hashtable - Save 2 as 3 of (Key (Picked unit).) in hashtable[3].
                • Else - Actions

 

Attachments

  • backup traderpg backup v11.w3m
    3.3 MB · Views: 2
Level 24
Joined
Feb 27, 2019
Messages
783
Derp. A few references are incorrectly using matching unit.

Matching unit is for filter functions. (When filtering which units to pick)
  • (Load 5 of (Key (Matching unit).) from hashtable[3].) Less than or equal to wood[(Load 3 of (Key (Load 1 of (Key (Picked unit).) in hashtable[3].).) from hashtable[1].)]
 
Level 9
Joined
Dec 1, 2010
Messages
346
Derp. A few references are incorrectly using matching unit.

Matching unit is for filter functions. (When filtering which units to pick)
  • (Load 5 of (Key (Matching unit).) from hashtable[3].) Less than or equal to wood[(Load 3 of (Key (Load 1 of (Key (Picked unit).) in hashtable[3].).) from hashtable[1].)]
So you never use it outside of the condition?

Initially i used picking unit but changing it seemed to fix the issue but i suppose that was a fake fix then lol since i still had problems afterwards

Edit: when i use picked unit in my trigger the value is somehow always 1 when loading even when i set the value to 3 or higher. This is the same issue i had before i tried fixing it by adding matching instead of picking. It's gettting a 1 from the hashtable when it should get a number equal to the one in the ability icon.


  • Unit Group - Pick every unit in tradePorts and do (Actions)
    • Loop - Actions
      • Set VariableSet portPos = (Position of (Picked unit))
      • Set VariableSet tempUnit = (Picked unit)
      • Unit Group - Pick every unit in (Units within 300.00 of portPos matching ((Unit-type of (Matching unit)) Equal to Transport Ship).) and do (Actions)
        • Loop - Actions
          • -------- If tradeship and going to homeport and port in range is homeportt --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Load 3 of (Key (Picked unit).) from hashtable[3].) Equal to 2
              • (Load 1 of (Key (Picked unit).) in hashtable[3].) Equal to tempUnit
            • Then - Actions
              • Game - Display to (All players) the text: Reached homeport pi...
              • -------- Check if tradegood is in stock --------
              • -------- wood --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Load 6 of (Key (Picked unit).) from hashtable[3].) Equal to 1
                  • (Load 5 of (Key (Picked unit).) from hashtable[3].) Less than or equal to wood[(Load 3 of (Key (Load 1 of (Key (Picked unit).) in hashtable[3].).) from hashtable[1].)]
                • Then - Actions
                  • Game - Display to (All players) the text: (Amount transported: + (String((Load 5 of (Key (Picked unit).) from hashtable[3].))))
                  • -------- If wood in stock > needed wood for transport --------
                  • -------- Set wood to new value --------
                  • Set VariableSet wood[(Load 3 of (Key (Load 1 of (Key (Picked unit).) in hashtable[3].).) from hashtable[1].)] = (wood[(Load 3 of (Key (Load 1 of (Key (Picked unit).) in hashtable[3].).) from hashtable[1].)] - (Load 5 of (Key (Picked unit).) from hashtable[3].))
                  • -------- Add item --------
                  • Hero - Create wood and give it to (Picked unit)
                  • Item - Set charges remaining in (Last created item) to (Load 5 of (Key (Picked unit).) from hashtable[3].)
                  • Item - Set charges remaining in (Last created item) to 3
                  • Hashtable - Save 1 as 3 of (Key (Picked unit).) in hashtable[3].
                • Else - Actions
                  • -------- Not enough wood in node --------
                  • Game - Display to (All players) the text: Not sufficient of s...
              • -------- stone --------
              • -------- food --------
            • Else - Actions
          • -------- If tradeship and going to destination port and port in range is destination port --------
          • Game - Display to (All players) the text: (String((Load 3 of (Key (Picked unit).) from hashtable[3].)))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Load 3 of (Key (Picked unit).) from hashtable[3].) Equal to 1
              • (Load 2 of (Key (Picked unit).) in hashtable[3].) Equal to tempUnit
            • Then - Actions
              • Game - Display to (All players) the text: Reached Destination...
              • Hashtable - Save 0 as 3 of (Key (Picked unit).) in hashtable[3].
              • Item - Create (Item-type of (Item carried by (Picked unit) in slot 1)) at (Center of (Playable map area))
              • Item - Set charges remaining in (Last created item) to (Charges remaining in (Item carried by (Picked unit) in slot 1))
              • Hero - Give (Last created item) to tempUnit
              • Item - Remove (Item carried by (Picked unit) in slot 1)
              • Hashtable - Save 2 as 3 of (Key (Picked unit).) in hashtable[3].
            • Else - Actions
      • Unit Group - Pick every unit in (Units within 300.00 of portPos.) and do (Actions)
        • Loop - Actions
          • -------- If tradeship and going to homeport and port in range is homeportt --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Picked unit)) Equal to Transport Ship
              • (Load 3 of (Key (Picked unit).) from hashtable[3].) Equal to 2
              • (Load 1 of (Key (Picked unit).) in hashtable[3].) Equal to tempUnit
            • Then - Actions
              • Set VariableSet shipUnit = (Picked unit)
              • Game - Display to (All players) the text: Reached homeport pi...
              • -------- Check if tradegood is in stock --------
              • -------- wood --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Load 6 of (Key shipUnit.) from hashtable[3].) Equal to 1
                  • (Load 5 of (Key shipUnit.) from hashtable[3].) Less than or equal to wood[(Load 3 of (Key (Load 1 of (Key shipUnit.) in hashtable[3].).) from hashtable[1].)]
                • Then - Actions
                  • -------- If wood in stock > needed wood for transport --------
                  • -------- Set wood to new value --------
                  • Set VariableSet wood[(Load 3 of (Key (Load 1 of (Key shipUnit.) in hashtable[3].).) from hashtable[1].)] = (wood[(Load 3 of (Key (Load 1 of (Key shipUnit.) in hashtable[3].).) from hashtable[1].)] - (Load 5 of (Key shipUnit.) from hashtable[3].))
                  • -------- Add item --------
                  • Hero - Create wood and give it to (Picked unit)
                  • Item - Set charges remaining in (Last created item) to (Load 5 of (Key shipUnit.) from hashtable[3].)
                  • Item - Set charges remaining in (Last created item) to 3
                  • Hashtable - Save 1 as 3 of (Key shipUnit.) in hashtable[3].
                • Else - Actions
                  • -------- Not enough wood in node --------
                  • Game - Display to (All players) the text: Not sufficient of s...
              • -------- stone --------
              • -------- food --------
            • Else - Actions
          • -------- If tradeship and going to destination port and port in range is destination port --------
          • Game - Display to (All players) the text: (String((Load 3 of (Key (Picked unit).) from hashtable[3].)))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Picked unit)) Equal to Transport Ship
              • (Load 3 of (Key (Picked unit).) from hashtable[3].) Equal to 1
              • (Load 2 of (Key (Picked unit).) in hashtable[3].) Equal to tempUnit
            • Then - Actions
              • Game - Display to (All players) the text: Reached Destination...
              • Hashtable - Save 0 as 3 of (Key (Picked unit).) in hashtable[3].
              • Item - Create (Item-type of (Item carried by (Picked unit) in slot 1)) at (Center of (Playable map area))
              • Item - Set charges remaining in (Last created item) to (Charges remaining in (Item carried by (Picked unit) in slot 1))
              • Hero - Give (Last created item) to tempUnit
              • Item - Remove (Item carried by (Picked unit) in slot 1)
              • Hashtable - Save 2 as 3 of (Key (Picked unit).) in hashtable[3].
            • Else - Actions
 
Last edited:
Level 9
Joined
Dec 1, 2010
Messages
346
Okay i'm really confused now. I did some further testing.


  • Initialize Transport amount to 1
    • Events
      • Unit - A unit Finishes training a unit
    • Conditions
      • (Unit-type of (Trained unit)) Equal to Transport Ship
    • Actions
      • Hashtable - Save 1 as 5 of (Key (Trained unit).) in hashtable[3].
      • Hashtable - Save 1 as 6 of (Key (Trained unit).) in hashtable[3].
When i changed the initialization for key 5 to 2
  • Hashtable - Save 2 as 5 of (Key (Trained unit).) in hashtable[3].
It always takes 2 for every ship instead of one.

Even though i have a seperate function that sets this hashtable whenever the spell button is clicked for that unit:

  • Set trade amount
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
    • Actions
      • -------- 1 --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Set amount transported: 1
        • Then - Actions
          • Unit - Add Set amount transported: 2 to (Casting unit)
          • Unit - Remove (Ability being cast) from (Casting unit)
          • Hashtable - Save 2 as 5 of (Key (Casting unit).) in hashtable[3].
        • Else - Actions
      • -------- 2 --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Set amount transported: 2
        • Then - Actions
          • Unit - Add Set amount transported: 3 to (Casting unit)
          • Unit - Remove (Ability being cast) from (Casting unit)
          • Hashtable - Save 3 as 5 of (Key (Casting unit).) in hashtable[3].
        • Else - Actions
      • -------- 3 --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Set amount transported: 3
        • Then - Actions
          • Unit - Add Set amount transported: 4 to (Casting unit)
          • Unit - Remove (Ability being cast) from (Casting unit)
          • Hashtable - Save 4 as 5 of (Key (Casting unit).) in hashtable[3].
        • Else - Actions
      • -------- 4 --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Set amount transported: 4
        • Then - Actions
          • Unit - Add Set amount transported: 5 to (Casting unit)
          • Unit - Remove (Ability being cast) from (Casting unit)
          • Hashtable - Save 5 as 5 of (Key (Casting unit).) in hashtable[3].
        • Else - Actions
      • -------- 5 --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Set amount transported: 5
        • Then - Actions
          • Unit - Add Set amount transported:6 to (Casting unit)
          • Unit - Remove (Ability being cast) from (Casting unit)
          • Hashtable - Save 6 as 5 of (Key (Casting unit).) in hashtable[3].
        • Else - Actions
      • -------- 6 --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Set amount transported:6
        • Then - Actions
          • Unit - Add Set amount transported:7 to (Casting unit)
          • Unit - Remove (Ability being cast) from (Casting unit)
          • Hashtable - Save 7 as 5 of (Key (Casting unit).) in hashtable[3].
        • Else - Actions
      • -------- 7 --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Set amount transported:7
        • Then - Actions
          • Unit - Add Set amount transported:8 to (Casting unit)
          • Unit - Remove (Ability being cast) from (Casting unit)
          • Hashtable - Save 8 as 5 of (Key (Casting unit).) in hashtable[3].
        • Else - Actions
      • -------- 8 --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Set amount transported:8
        • Then - Actions
          • Unit - Add Set amount transported:9 to (Casting unit)
          • Unit - Remove (Ability being cast) from (Casting unit)
          • Hashtable - Save 9 as 5 of (Key (Casting unit).) in hashtable[3].
        • Else - Actions
      • -------- 9 --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Set amount transported:9
        • Then - Actions
          • Unit - Add Set amount transported: 1 to (Casting unit)
          • Unit - Remove (Ability being cast) from (Casting unit)
          • Hashtable - Save 1 as 5 of (Key (Casting unit).) in hashtable[3].
        • Else - Actions
      • Game - Display to (All players) the text: (String((Load 5 of (Key (Casting unit).) from hashtable[3].)))
For some reason when i load key 5 from this trigger it displays the correct amount but in the unload trigger it just goes to the default that was set after training. even if after training it i increased the value for the casting unit..
  • Game - Display to (All players) the text: (Amount transported: + (String((Load 5 of (Key (Picked unit).) from hashtable[3].))))
from
  • Unit Group - Pick every unit in tradePorts and do (Actions)
    • Loop - Actions
      • Set VariableSet portPos = (Position of (Picked unit))
      • Set VariableSet tempUnit = (Picked unit)
      • Unit Group - Pick every unit in (Units within 300.00 of portPos matching ((Unit-type of (Matching unit)) Equal to Transport Ship).) and do (Actions)
        • Loop - Actions
          • -------- If tradeship and going to homeport and port in range is homeportt --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Load 3 of (Key (Picked unit).) from hashtable[3].) Equal to 2
              • (Load 1 of (Key (Picked unit).) in hashtable[3].) Equal to tempUnit
            • Then - Actions
              • Game - Display to (All players) the text: Reached homeport pi...
              • -------- Check if tradegood is in stock --------
              • -------- wood --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Load 6 of (Key (Picked unit).) from hashtable[3].) Equal to 1
                  • (Load 5 of (Key (Picked unit).) from hashtable[3].) Less than or equal to wood[(Load 3 of (Key (Load 1 of (Key (Picked unit).) in hashtable[3].).) from hashtable[1].)]
                • Then - Actions
                  • Game - Display to (All players) the text: (Amount transported: + (String((Load 5 of (Key (Picked unit).) from hashtable[3].))))
                  • -------- If wood in stock > needed wood for transport --------
                  • -------- Set wood to new value --------
                  • Set VariableSet wood[(Load 3 of (Key (Load 1 of (Key (Picked unit).) in hashtable[3].).) from hashtable[1].)] = (wood[(Load 3 of (Key (Load 1 of (Key (Picked unit).) in hashtable[3].).) from hashtable[1].)] - (Load 5 of (Key (Picked unit).) from hashtable[3].))
                  • -------- Add item --------
                  • Hero - Create wood and give it to (Picked unit)
                  • Item - Set charges remaining in (Last created item) to (Load 5 of (Key (Picked unit).) from hashtable[3].)
                  • Item - Set charges remaining in (Last created item) to 3
                  • Hashtable - Save 1 as 3 of (Key (Picked unit).) in hashtable[3].
                • Else - Actions
                  • -------- Not enough wood in node --------
                  • Game - Display to (All players) the text: Not sufficient of s...
              • -------- stone --------
              • -------- food --------
            • Else - Actions
          • -------- If tradeship and going to destination port and port in range is destination port --------
          • Game - Display to (All players) the text: (String((Load 3 of (Key (Picked unit).) from hashtable[3].)))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Load 3 of (Key (Picked unit).) from hashtable[3].) Equal to 1
              • (Load 2 of (Key (Picked unit).) in hashtable[3].) Equal to tempUnit
            • Then - Actions
              • Game - Display to (All players) the text: Reached Destination...
              • Hashtable - Save 0 as 3 of (Key (Picked unit).) in hashtable[3].
              • Item - Create (Item-type of (Item carried by (Picked unit) in slot 1)) at (Center of (Playable map area))
              • Item - Set charges remaining in (Last created item) to (Charges remaining in (Item carried by (Picked unit) in slot 1))
              • Hero - Give (Last created item) to tempUnit
              • Item - Remove (Item carried by (Picked unit) in slot 1)
              • Hashtable - Save 2 as 3 of (Key (Picked unit).) in hashtable[3].
            • Else - Actions
      • Unit Group - Pick every unit in (Units within 300.00 of portPos.) and do (Actions)
        • Loop - Actions
          • -------- If tradeship and going to homeport and port in range is homeportt --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Picked unit)) Equal to Transport Ship
              • (Load 3 of (Key (Picked unit).) from hashtable[3].) Equal to 2
              • (Load 1 of (Key (Picked unit).) in hashtable[3].) Equal to tempUnit
            • Then - Actions
              • Set VariableSet shipUnit = (Picked unit)
              • Game - Display to (All players) the text: Reached homeport pi...
              • -------- Check if tradegood is in stock --------
              • -------- wood --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Load 6 of (Key shipUnit.) from hashtable[3].) Equal to 1
                  • (Load 5 of (Key shipUnit.) from hashtable[3].) Less than or equal to wood[(Load 3 of (Key (Load 1 of (Key shipUnit.) in hashtable[3].).) from hashtable[1].)]
                • Then - Actions
                  • -------- If wood in stock > needed wood for transport --------
                  • -------- Set wood to new value --------
                  • Set VariableSet wood[(Load 3 of (Key (Load 1 of (Key shipUnit.) in hashtable[3].).) from hashtable[1].)] = (wood[(Load 3 of (Key (Load 1 of (Key shipUnit.) in hashtable[3].).) from hashtable[1].)] - (Load 5 of (Key shipUnit.) from hashtable[3].))
                  • -------- Add item --------
                  • Hero - Create wood and give it to (Picked unit)
                  • Item - Set charges remaining in (Last created item) to (Load 5 of (Key shipUnit.) from hashtable[3].)
                  • Item - Set charges remaining in (Last created item) to 3
                  • Hashtable - Save 1 as 3 of (Key shipUnit.) in hashtable[3].
                • Else - Actions
                  • -------- Not enough wood in node --------
                  • Game - Display to (All players) the text: Not sufficient of s...
              • -------- stone --------
              • -------- food --------
            • Else - Actions
          • -------- If tradeship and going to destination port and port in range is destination port --------
          • Game - Display to (All players) the text: (String((Load 3 of (Key (Picked unit).) from hashtable[3].)))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Picked unit)) Equal to Transport Ship
              • (Load 3 of (Key (Picked unit).) from hashtable[3].) Equal to 1
              • (Load 2 of (Key (Picked unit).) in hashtable[3].) Equal to tempUnit
            • Then - Actions
              • Game - Display to (All players) the text: Reached Destination...
              • Hashtable - Save 0 as 3 of (Key (Picked unit).) in hashtable[3].
              • Item - Create (Item-type of (Item carried by (Picked unit) in slot 1)) at (Center of (Playable map area))
              • Item - Set charges remaining in (Last created item) to (Charges remaining in (Item carried by (Picked unit) in slot 1))
              • Hero - Give (Last created item) to tempUnit
              • Item - Remove (Item carried by (Picked unit) in slot 1)
              • Hashtable - Save 2 as 3 of (Key (Picked unit).) in hashtable[3].
            • Else - Actions
Always displays the value set during initialisation and ignores the set trade amount values.



Here's my test with :
  • Initialize Transport amount to 1
    • Events
      • Unit - A unit Finishes training a unit
    • Conditions
      • (Unit-type of (Trained unit)) Equal to Transport Ship
    • Actions
      • Hashtable - Save 2 as 5 of (Key (Trained unit).) in hashtable[3].
      • Hashtable - Save 1 as 6 of (Key (Trained unit).) in hashtable[3].



So TLDR:
Even though the checks in:


  • Set trade amount
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
    • Actions
      • -------- 1 --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Set amount transported: 1
        • Then - Actions
          • Unit - Add Set amount transported: 2 to (Casting unit)
          • Unit - Remove (Ability being cast) from (Casting unit)
          • Hashtable - Save 2 as 5 of (Key (Casting unit).) in hashtable[3].
        • Else - Actions
      • -------- 2 --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Set amount transported: 2
        • Then - Actions
          • Unit - Add Set amount transported: 3 to (Casting unit)
          • Unit - Remove (Ability being cast) from (Casting unit)
          • Hashtable - Save 3 as 5 of (Key (Casting unit).) in hashtable[3].
        • Else - Actions
      • -------- 3 --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Set amount transported: 3
        • Then - Actions
          • Unit - Add Set amount transported: 4 to (Casting unit)
          • Unit - Remove (Ability being cast) from (Casting unit)
          • Hashtable - Save 4 as 5 of (Key (Casting unit).) in hashtable[3].
        • Else - Actions
      • -------- 4 --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Set amount transported: 4
        • Then - Actions
          • Unit - Add Set amount transported: 5 to (Casting unit)
          • Unit - Remove (Ability being cast) from (Casting unit)
          • Hashtable - Save 5 as 5 of (Key (Casting unit).) in hashtable[3].
        • Else - Actions
      • -------- 5 --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Set amount transported: 5
        • Then - Actions
          • Unit - Add Set amount transported:6 to (Casting unit)
          • Unit - Remove (Ability being cast) from (Casting unit)
          • Hashtable - Save 6 as 5 of (Key (Casting unit).) in hashtable[3].
        • Else - Actions
      • -------- 6 --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Set amount transported:6
        • Then - Actions
          • Unit - Add Set amount transported:7 to (Casting unit)
          • Unit - Remove (Ability being cast) from (Casting unit)
          • Hashtable - Save 7 as 5 of (Key (Casting unit).) in hashtable[3].
        • Else - Actions
      • -------- 7 --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Set amount transported:7
        • Then - Actions
          • Unit - Add Set amount transported:8 to (Casting unit)
          • Unit - Remove (Ability being cast) from (Casting unit)
          • Hashtable - Save 8 as 5 of (Key (Casting unit).) in hashtable[3].
        • Else - Actions
      • -------- 8 --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Set amount transported:8
        • Then - Actions
          • Unit - Add Set amount transported:9 to (Casting unit)
          • Unit - Remove (Ability being cast) from (Casting unit)
          • Hashtable - Save 9 as 5 of (Key (Casting unit).) in hashtable[3].
        • Else - Actions
      • -------- 9 --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Set amount transported:9
        • Then - Actions
          • Unit - Add Set amount transported: 1 to (Casting unit)
          • Unit - Remove (Ability being cast) from (Casting unit)
          • Hashtable - Save 1 as 5 of (Key (Casting unit).) in hashtable[3].
        • Else - Actions
      • Game - Display to (All players) the text: (String((Load 5 of (Key (Casting unit).) from hashtable[3].)))

indicate that it's correctly being updated, when i load the hash value in my unload trigger it only displays the initialized amount after training.
 
Last edited:
Level 24
Joined
Feb 27, 2019
Messages
783
Matching unit is only to be used in the conditions for the pick every unit action.

The event response Casting unit is only valid for as long as an ability is being cast. Something that works better is to rely on more robust event responses such as Triggering unit or better yet, setting your unit to a variable at the start of the trigger.

Its pretty hard for me to understand which values youre saving and what they mean. You could create integer variables with fitting names and set they value to a number to make it easier, at least for others, to understand.
This:
  • (Load 3 of (Key (Picked unit).) from hashtable[3].) Equal to 2
Becomes:
  • (Load CURRENT_ORDER of (Key (Picked unit).) from hashtable[TRANSPORT_SHIPS].) Equal to ORDER_RETURN
The reason for the large letters is that its the common syntax used by blizzard for readonly constant variables. They are set at map init and never changed during the game. Its not even possible to change them but that limitation cant be set on udg_ variables so well just have to remember never to change them :)
 
Last edited:
Level 9
Joined
Dec 1, 2010
Messages
346
EDIT:
  • unload Homeport
    • Events
      • Time - Every 0.50 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in tradePorts and do (Actions)
        • Loop - Actions
          • Set VariableSet portPos = (Position of (Picked unit))
          • Set VariableSet tempUnit = (Picked unit)
          • Unit Group - Pick every unit in (Units within 300.00 of (Position of tempUnit).) and do (Actions)
            • Loop - Actions
              • -------- If tradeship and going to homeport and port in range is homeportt --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Unit-type of (Picked unit)) Equal to Transport Ship
                  • (Load CURRENT_ORDER of (Key (Picked unit).) from hashtable[HASHTABLE_TRANSPORT].) Equal to ORDER_RETURN
                  • (Load HANDLE_HOMEPORT of (Key (Picked unit).) in hashtable[HASHTABLE_TRANSPORT].) Equal to tempUnit
                • Then - Actions
                  • Game - Display to (All players) the text: Reached homeport pi...
                  • -------- Check if tradegood is in stock --------
                  • -------- wood --------
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Load TRADEGOOD_TYPE of (Key (Picked unit).) from hashtable[HASHTABLE_TRANSPORT].) Equal to TRADEGOOD_WOOD
                      • (Load TRADEGOOD_AMOUNT of (Key (Picked unit).) from hashtable[HASHTABLE_TRANSPORT].) Less than or equal to wood[(Load TRADENODE_ID of (Key (Load HANDLE_HOMEPORT of (Key (Picked unit).) in hashtable[HASHTABLE_TRANSPORT].).) from hashtable[HASHTABLE_BUILDING].)]
                    • Then - Actions
                      • Game - Display to (All players) the text: (Amount transported: + (String((Load TRADEGOOD_AMOUNT of (Key (Picked unit).) from hashtable[HASHTABLE_TRANSPORT].))))
                      • -------- If wood in stock > needed wood for transport --------
                      • -------- Set wood to new value --------
                      • Set VariableSet wood[(Load TRADENODE_ID of (Key (Load HANDLE_HOMEPORT of (Key (Picked unit).) in hashtable[HASHTABLE_TRANSPORT].).) from hashtable[HASHTABLE_BUILDING].)] = (wood[(Load TRADENODE_ID of (Key (Load HANDLE_HOMEPORT of (Key (Picked unit).) in hashtable[HASHTABLE_TRANSPORT].).) from hashtable[HASHTABLE_BUILDING].)] - (Load TRADEGOOD_AMOUNT of (Key (Picked unit).) from hashtable[HASHTABLE_TRANSPORT].))
                      • -------- Add item --------
                      • Hero - Create wood and give it to (Picked unit)
                      • Item - Set charges remaining in (Last created item) to (Load TRADEGOOD_AMOUNT of (Key (Picked unit).) from hashtable[HASHTABLE_TRANSPORT].)
                      • Hashtable - Save ORDER_DELIVER as CURRENT_ORDER of (Key (Picked unit).) in hashtable[HASHTABLE_TRANSPORT].
                    • Else - Actions
                      • -------- Not enough wood in node --------
                      • Game - Display to (All players) the text: Not sufficient of s...
                  • -------- stone --------
                  • -------- food --------
                • Else - Actions
              • -------- If tradeship and going to destination port and port in range is destination port --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Unit-type of (Picked unit)) Equal to Transport Ship
                  • (Load CURRENT_ORDER of (Key (Picked unit).) from hashtable[HASHTABLE_TRANSPORT].) Equal to ORDER_DELIVER
                  • (Load HANDLE_DESTINATIONPORT of (Key (Picked unit).) in hashtable[HASHTABLE_TRANSPORT].) Equal to tempUnit
                • Then - Actions
                  • Game - Display to (All players) the text: Reached Destination...
                  • Hashtable - Save ORDER_NONE as CURRENT_ORDER of (Key (Picked unit).) in hashtable[HASHTABLE_TRANSPORT].
                  • Item - Create (Item-type of (Item carried by (Picked unit) in slot 1)) at (Center of (Playable map area))
                  • Item - Set charges remaining in (Last created item) to (Charges remaining in (Item carried by (Picked unit) in slot 1))
                  • Hero - Give (Last created item) to tempUnit
                  • Item - Remove (Item carried by (Picked unit) in slot 1)
                  • Hashtable - Save ORDER_RETURN as CURRENT_ORDER of (Key (Picked unit).) in hashtable[HASHTABLE_TRANSPORT].
                • Else - Actions

  • Initialize Transport amount to 1
    • Events
      • Unit - A unit Finishes training a unit
    • Conditions
      • (Unit-type of (Trained unit)) Equal to Transport Ship
    • Actions
      • Hashtable - Save 2 as TRADEGOOD_AMOUNT of (Key (Trained unit).) in hashtable[HASHTABLE_TRANSPORT].
      • Hashtable - Save TRADEGOOD_WOOD as TRADEGOOD_TYPE of (Key (Trained unit).) in hashtable[HASHTABLE_TRANSPORT].

  • Set trade amount
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
    • Actions
      • -------- 1 --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Set amount transported: 1
        • Then - Actions
          • Unit - Add Set amount transported: 2 to (Casting unit)
          • Unit - Remove (Ability being cast) from (Casting unit)
          • Hashtable - Save 2 as TRADEGOOD_AMOUNT of (Key (Casting unit).) in hashtable[HASHTABLE_TRANSPORT].
        • Else - Actions
      • -------- 2 --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Set amount transported: 2
        • Then - Actions
          • Unit - Add Set amount transported: 3 to (Casting unit)
          • Unit - Remove (Ability being cast) from (Casting unit)
          • Hashtable - Save 3 as TRADEGOOD_AMOUNT of (Key (Casting unit).) in hashtable[HASHTABLE_TRANSPORT].
        • Else - Actions
      • -------- 3 --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Set amount transported: 3
        • Then - Actions
          • Unit - Add Set amount transported: 4 to (Casting unit)
          • Unit - Remove (Ability being cast) from (Casting unit)
          • Hashtable - Save 4 as TRADEGOOD_AMOUNT of (Key (Casting unit).) in hashtable[HASHTABLE_TRANSPORT].
        • Else - Actions
      • -------- 4 --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Set amount transported: 4
        • Then - Actions
          • Unit - Add Set amount transported: 5 to (Casting unit)
          • Unit - Remove (Ability being cast) from (Casting unit)
          • Hashtable - Save 5 as TRADEGOOD_AMOUNT of (Key (Casting unit).) in hashtable[HASHTABLE_TRANSPORT].
        • Else - Actions
      • -------- 5 --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Set amount transported: 5
        • Then - Actions
          • Unit - Add Set amount transported:6 to (Casting unit)
          • Unit - Remove (Ability being cast) from (Casting unit)
          • Hashtable - Save 6 as TRADEGOOD_AMOUNT of (Key (Casting unit).) in hashtable[HASHTABLE_TRANSPORT].
        • Else - Actions
      • -------- 6 --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Set amount transported:6
        • Then - Actions
          • Unit - Add Set amount transported:7 to (Casting unit)
          • Unit - Remove (Ability being cast) from (Casting unit)
          • Hashtable - Save 7 as TRADEGOOD_AMOUNT of (Key (Casting unit).) in hashtable[HASHTABLE_TRANSPORT].
        • Else - Actions
      • -------- 7 --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Set amount transported:7
        • Then - Actions
          • Unit - Add Set amount transported:8 to (Casting unit)
          • Unit - Remove (Ability being cast) from (Casting unit)
          • Hashtable - Save 8 as TRADEGOOD_AMOUNT of (Key (Casting unit).) in hashtable[HASHTABLE_TRANSPORT].
        • Else - Actions
      • -------- 8 --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Set amount transported:8
        • Then - Actions
          • Unit - Add Set amount transported:9 to (Casting unit)
          • Unit - Remove (Ability being cast) from (Casting unit)
          • Hashtable - Save 9 as TRADEGOOD_AMOUNT of (Key (Casting unit).) in hashtable[HASHTABLE_TRANSPORT].
        • Else - Actions
      • -------- 9 --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Set amount transported:9
        • Then - Actions
          • Unit - Add Set amount transported: 1 to (Casting unit)
          • Unit - Remove (Ability being cast) from (Casting unit)
          • Hashtable - Save 1 as TRADEGOOD_AMOUNT of (Key (Casting unit).) in hashtable[HASHTABLE_TRANSPORT].
        • Else - Actions
      • Game - Display to (All players) the text: (String((Load TRADEGOOD_AMOUNT of (Key (Casting unit).) from hashtable[HASHTABLE_TRANSPORT].)))

also added the map with these 3 triggers clarified.

So TLDR: the TRADEGOOD_AMOUNT is being read as 2 . which is the amount set during inittalize trigger. even though it should be set to a different amount when i click on the ability to set the amount (which only the tradeship has).

When i click on the ability it correctly displays the amount for that ship. but for some reason it won't get the updated TRADEGOOD_AMOUNT in the unload function when i load the hashtable value there. even though it should be referencing the same transport ship.

the graphic.png
 

Attachments

  • backup traderpg backup v12.w3m
    3.3 MB · Views: 2
Last edited:
Level 9
Joined
Dec 1, 2010
Messages
346
When you interrupt the casting of an ability and that ability is Ability being cast, the refence Casting unit is lost. You can double check Key(Casting unit) or Casting unit with a debug message. If (Casting unit) is null (No unit) the data is saved to Key(0) instead of the intended Key.
ah, is that why i'm still getting a message when referencing the casting unit? it's just retrieving key (0) all the time?

How can i fix this? Would something like
  • Set VariableSet tempUnit = (Casting unit)
be sufficient?

As in put it here, and then replace all the casting unit references with tempUnit? or would the same issue still be present by saving key (0)) to the variable??
  • Set trade amount
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
    • Actions
      • Set VariableSet tempUnit = (Casting unit)
      • -------- 1 --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Set amount transported: 1
        • Then - Actions
          • Unit - Add Set amount transported: 2 to (Casting unit)
          • Unit - Remove (Ability being cast) from (Casting unit)
          • Hashtable - Save 2 as TRADEGOOD_AMOUNT of (Key (Casting unit).) in hashtable[HASHTABLE_TRANSPORT].
        • Else - Actions
      • -------- 2 --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Set amount transported: 2
        • Then - Actions
          • Unit - Add Set amount transported: 3 to (Casting unit)
          • Unit - Remove (Ability being cast) from (Casting unit)
          • Hashtable - Save 3 as TRADEGOOD_AMOUNT of (Key (Casting unit).) in hashtable[HASHTABLE_TRANSPORT].
        • Else - Actions
      • -------- 3 --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Set amount transported: 3
        • Then - Actions
          • Unit - Add Set amount transported: 4 to (Casting unit)
          • Unit - Remove (Ability being cast) from (Casting unit)
          • Hashtable - Save 4 as TRADEGOOD_AMOUNT of (Key (Casting unit).) in hashtable[HASHTABLE_TRANSPORT].
        • Else - Actions
      • -------- 4 --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Set amount transported: 4
        • Then - Actions
          • Unit - Add Set amount transported: 5 to (Casting unit)
          • Unit - Remove (Ability being cast) from (Casting unit)
          • Hashtable - Save 5 as TRADEGOOD_AMOUNT of (Key (Casting unit).) in hashtable[HASHTABLE_TRANSPORT].
        • Else - Actions
      • -------- 5 --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Set amount transported: 5
        • Then - Actions
          • Unit - Add Set amount transported:6 to (Casting unit)
          • Unit - Remove (Ability being cast) from (Casting unit)
          • Hashtable - Save 6 as TRADEGOOD_AMOUNT of (Key (Casting unit).) in hashtable[HASHTABLE_TRANSPORT].
        • Else - Actions
      • -------- 6 --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Set amount transported:6
        • Then - Actions
          • Unit - Add Set amount transported:7 to (Casting unit)
          • Unit - Remove (Ability being cast) from (Casting unit)
          • Hashtable - Save 7 as TRADEGOOD_AMOUNT of (Key (Casting unit).) in hashtable[HASHTABLE_TRANSPORT].
        • Else - Actions
      • -------- 7 --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Set amount transported:7
        • Then - Actions
          • Unit - Add Set amount transported:8 to (Casting unit)
          • Unit - Remove (Ability being cast) from (Casting unit)
          • Hashtable - Save 8 as TRADEGOOD_AMOUNT of (Key (Casting unit).) in hashtable[HASHTABLE_TRANSPORT].
        • Else - Actions
      • -------- 8 --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Set amount transported:8
        • Then - Actions
          • Unit - Add Set amount transported:9 to (Casting unit)
          • Unit - Remove (Ability being cast) from (Casting unit)
          • Hashtable - Save 9 as TRADEGOOD_AMOUNT of (Key (Casting unit).) in hashtable[HASHTABLE_TRANSPORT].
        • Else - Actions
      • -------- 9 --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Set amount transported:9
        • Then - Actions
          • Unit - Add Set amount transported: 1 to (Casting unit)
          • Unit - Remove (Ability being cast) from (Casting unit)
          • Hashtable - Save 1 as TRADEGOOD_AMOUNT of (Key (Casting unit).) in hashtable[HASHTABLE_TRANSPORT].
        • Else - Actions
      • Game - Display to (All players) the text: (String((Load TRADEGOOD_AMOUNT of (Key (Casting unit).) from hashtable[HASHTABLE_TRANSPORT].)))

EDIT: After very fast testting it seems to work!!!

I have to go somewhere now but will do some more testing once im back but i'm ecstatic haha TY!
 
Last edited:
Level 9
Joined
Dec 1, 2010
Messages
346
Just referencing Triggering Unit directly would also work, as that response is not lost in the same way Casting Unit is. There's generally no reason to use a different response if Triggering Unit will work.
well, when i just started out i used triggering unit as a response to everything and none of my triggers worked haha!

I guess i'm not sure where it does and doesn't work so i stopped using it alll together since it's no always clear to me which unit it references
 
Level 24
Joined
Feb 27, 2019
Messages
783
well, when i just started out i used triggering unit as a response to everything and none of my triggers worked haha!

I guess i'm not sure where it does and doesn't work so i stopped using it alll together since it's no always clear to me which unit it references
How could you do that to poor Triggering unit? Leave it in the dark to freeze and suffer? Its time to give old Triggering unit a hug and bring it back to your warm embrace!! :grin:

Triggering unit is the A unit that triggers the event in A unit ... events.
A unit Dies: Triggering unit = Dying unit
A unit Starts the effect on an ability: Triggering unit = Casting unit
A unit
Is issued an order: Triggering unit = Ordered unit
A unit Is attacked: Triggering unit = Attacked unit
A unit Sells a unit: Triggering unit = Selling unit

Theres at least one exception but the editor is nice to tell you with the nifty grey info text that is displayed for many of the windows in GUI.
exception player event triggering unit.png
 
Top