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

Hashtable problem

Status
Not open for further replies.
Level 12
Joined
Sep 11, 2011
Messages
1,176
hello everyone!

i'm helping someone to make a system that kills all unit inside a transport when the transport died. but it seems that my trigger didn't work properly. take a look :

  • Loading Units
    • Events
      • Unit - A unit Is loaded into a transport
    • Conditions
    • Actions
      • For each (Integer IntegerVariable) from 1 to TransportCount, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Transporting unit) Equal to Transport[IntegerVariable]
            • Then - Actions
              • Set PassengerCount[IntegerVariable] = (PassengerCount[IntegerVariable] + 1)
              • Game - Display to (All players) the text: (Transport name : + ((Name of Transport[IntegerVariable]) + ( Number + (String(IntegerVariable)))))
              • Game - Display to (All players) the text: (Number of Passengers : + (String(PassengerCount[IntegerVariable])))
              • Hashtable - Save Handle Of(Triggering unit) as IntegerVariable of PassengerCount[IntegerVariable] in hash
            • Else - Actions
  • Dead Transports
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • For each (Integer IntegerVariable) from 1 to TransportCount, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Triggering unit) Equal to Transport[IntegerVariable]
            • Then - Actions
              • For each (Integer IntegerVariable2) from 1 to PassengerCount[IntegerVariable], do (Actions)
                • Loop - Actions
                  • Game - Display to (All players) the text: (Name of (Load IntegerVariable of IntegerVariable2 in hash))
                  • Unit - Kill (Load IntegerVariable of IntegerVariable2 in hash)
            • Else - Actions
the hashtable should save all unit that's loaded into the transport
  • Hashtable - Save Handle Of(Triggering unit) as IntegerVariable of PassengerCount[IntegerVariable] in hash
but the hashtable only load 1 unit, anybody know what's the problem ?

P.S i already create a hashtable, and make a trigger that detects when the transport is in the map.
 
Level 12
Joined
Sep 11, 2011
Messages
1,176
Because when you save them to a new unit, it overwrites them.
You might need Indexing for this (you do know the difference between Unit Indexer and Indexing, right ?)

  • Hashtable - Save Handle Of(Triggering unit) as IntegerVariable of PassengerCount[IntegerVariable] in hash
but this won't overwrite anything, since for every unit that is loaded into a transport, the value of PassengerCount[IntegerVariable] will be increased by 1.

thus it will save like this

Load first unit
save to 1 of 1 in hash
Load second unit
save to 1 of 2 in hash
Load third unit
save to 1 of 3 in hash
Load n unit
save to 1 of n in hash

P.s i still can't differ Unit Indexer and Indexing (i can differ Hashtable and Unit Indexer though), i thought my trigger already use indexing @_@
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
Wait, which unit is holding the data ???

It should be;
Save Value as childKey of parentKey in Hashtable

The way I see it, your parentKey... is an Integer, which does not saves to anything ???
It should be saved to the transport;
  • Custom script: set udg_parentKey = GetHandleId(udg_YourTransport)
  • Hashtable - Save Handle OfLoadedUnit as 0 of parentKey in hash
This way, the Unit is saved to the Transport (but will overwrite it).
 
Level 12
Joined
Sep 11, 2011
Messages
1,176
thanks for that, now it looks like this, but it still save only one unit. Do i need to save the PassengerCount[IntegerVariable] into the hashtable too? @_@

  • Loading Units
    • Events
      • Unit - A unit Is loaded into a transport
    • Conditions
    • Actions
      • For each (Integer IntegerVariable) from 1 to TransportCount, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Transporting unit) Equal to Transport[IntegerVariable]
            • Then - Actions
              • Set PassengerCount[IntegerVariable] = (PassengerCount[IntegerVariable] + 1)
              • Game - Display to (All players) the text: (Transport name : + ((Name of Transport[IntegerVariable]) + ( Number + (String(IntegerVariable)))))
              • Game - Display to (All players) the text: (Number of Passengers : + (String(PassengerCount[IntegerVariable])))
              • Set HandleId = (Key (Transporting unit))
              • Hashtable - Save Handle Of(Triggering unit) as PassengerCount[IntegerVariable] of HandleId in hash
            • Else - Actions
  • Dead Transports
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • For each (Integer IntegerVariable) from 1 to TransportCount, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Triggering unit) Equal to Transport[IntegerVariable]
            • Then - Actions
              • Set HandleId = (Key (Triggering unit))
              • For each (Integer IntegerVariable2) from 1 to PassengerCount[IntegerVariable], do (Actions)
                • Loop - Actions
                  • Game - Display to (All players) the text: (Name of (Load IntegerVariable2 of HandleId in hash))
                  • Unit - Kill (Load IntegerVariable2 of HandleId in hash)
            • Else - Actions
P.S envy you much, you have most of flexibility on using custom scripts @_@
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
As I said, you must use Indexing, therefore you're able to save in a stacking manner.
Hashtable (Unit Indexer) allows the data to be saved, but will overwrite it if it's saved to the same unit.

Indexing is the best way :/

EDIT:
Wait, I'll try something from hashtable.
 
Level 12
Joined
Sep 11, 2011
Messages
1,176
As I said, you must use Indexing, therefore you're able to save in a stacking manner.
Hashtable (Unit Indexer) allows the data to be saved, but will overwrite it if it's saved to the same unit.

Indexing is the best way :/

EDIT:
Wait, I'll try something from hashtable.

it seems like i cannot do anything with hashtable anymore since i learned Unit Indexer, all my trigger with saving and loading using hashtable failed to work.
 
Status
Not open for further replies.
Top