Storing/Retrieving Information from a Hashtable

Status
Not open for further replies.
Level 5
Joined
Aug 12, 2010
Messages
149
I read the hashtable/mui tutorial and while it was very helpful I can't seem to make this work. I think I know what I want to do, but I don't know how to use WC3 triggers to do it. I am attempting to create a trigger that, creates 60 dummies evenly spaced in a circle around the caster and then connects each dummy to the one 6 places ahead of it with a mana link spell. It will look similar to the bottom right polygram on this page but with more points. I can create the circle of 60 dummies, but I'm having trouble using a hashtable to store/recover their handles. As I undertstand it, a hashtable is like a 2d array. What I want to do is this:

Create a dummy at (r, theta).
Store the handle of the dummy in a hashtable at (A, c).
Increment theta by 6 degrees.
Increment A by 1
Keep c constant.
Repeat 60 times

Each dummy will be saved in the hashtable along with a value of A that describes its position in the ring of dummies. Then I should be able order the unit described by the value (A, c) to Mana Link the value (A+6, c). It's not working the way I have it set up, though. The dummies are created but nothing happens.

  • Discordance
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Discordance (K)
    • Actions
      • Set K_Discordance_Caster = (Triggering unit)
      • Set K_Discordance_Owner = (Owner of (Triggering unit))
      • Set K_Discordance_Locations[1] = (Position of K_Discordance_Caster)
      • -------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------
      • -------- ============================= CREATE THE RING DUMMIES ============================= --------
      • -------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------
      • For each (Integer A) from 1 to (Integer(K_Discordance_Params[1])), do (Actions)
        • Loop - Actions
          • Set K_Discordance_Iteration[1] = (Integer A)
          • Set K_Discordance_Locations[2] = (K_Discordance_Locations[1] offset by K_Discordance_Params[2] towards ((Real(K_Discordance_Iteration[1])) x K_Discordance_Theta) degrees)
          • Unit - Create 1 Dummy (Discordance) for K_Discordance_Owner at K_Discordance_Locations[2] facing K_Discordance_Locations[1]
          • Unit - Add a 35.00 second Generic expiration timer to (Last created unit)
          • Unit - Add K - Discordance Ring FX to (Last created unit)
          • Hashtable - Save Handle Of(Last created unit) as K_Discordance_Iteration[1] of (Key Discordance Ring Units) in K_Discordance_Hash
          • Custom script: call RemoveLocation(udg_K_Discordance_Locations[2])
      • -------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------
      • -------- ============================= CREATE THE RING SFX ============================= --------
      • -------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------
      • For each (Integer A) from 1 to (Integer(K_Discordance_Params[1])), do (Actions)
        • Loop - Actions
          • -------- Linking the points on the ring of dummies --------
          • Set K_Discordance_Iteration[1] = (Integer A)
          • Set K_Discordance_Iteration[2] = ((K_Discordance_Iteration[1] + (Integer(K_Discordance_Params[3]))) mod (Integer(K_Discordance_Params[1])))
          • Set K_Discordance_RingUnit[1] = (Load K_Discordance_Iteration[1] of (Key Discordance Ring Units) in K_Discordance_Hash)
          • Set K_Discordance_RingUnit[2] = (Load K_Discordance_Iteration[2] of (Key Discordance Ring Units) in K_Discordance_Hash)
          • Unit - Order K_Discordance_RingUnit[1] to Human Priest - Inner Fire K_Discordance_RingUnit[2]
K_Discordance_Params{1] = 60, it's the number of points in the polygram
K_Discordance_Params{2] = 500, it's the distance from the caster to each point
K_Discordance_Params{3] = 6, it's the number of points that are skipped when connecting them with mana link
 
this trigger will create 60 dummies around the caster...take note that this is JUST A SAMPLE and must be edited based on what you want...

  • Dummies 60
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Thunder Clap
    • Actions
      • Set Caster = (Triggering unit)
      • Set Degrees = 0.00
      • Set CarterPnt = (Position of Caster)
      • For each (Integer Int) from 1 to 60, do (Actions)
        • Loop - Actions
          • Unit - Create 1 Footman for (Owner of Caster) at (CarterPnt offset by 750.00 towards Degrees degrees) facing Default building facing degrees
          • Set Degrees = (Degrees + 6.00)
 
this trigger will create 60 dummies around the caster...take note that this is JUST A SAMPLE and must be edited based on what you want...

Thanks, but I've already got that part working. What I need is to save each individual dummy into a hashtable in the order it was created. and then be able to recall it in that order.

Think of it this way: I'm creating a dummy at every "minute" on a clock and later ordering the dummy at 0:00 to cast a spell on the dummy at 0:06, 0:01 cast on 0:07, 0:02 cast on 0:08 and so on...

I can get information that identifies a specific dummy unit and its position in the ring of dummies, but I'm having problems saving and/or loading this information to and from the hashtable.
 
I think you dont need hashtables for this...wait Im gonna try it without hashtables...

EDIT: OK I was wrong, coz I'm using Hash now :)

First, remove the INVULNERABLE & LOCUST ability of the dummy unit, second I created a chain lightning spell...

the trigger will do Clock lightning animation...dummy1 will cast the spell to dummy2 and so on until reaches 60 dummies...

  • Clock
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Thunder Clap
    • Actions
      • -------- NOTE: WAIT is for testing purposes only, remove it if you want... --------
      • Set Caster = (Triggering unit)
      • Set Degrees = 0.00
      • Set Point = (Position of Caster)
      • For each (Integer LoopInd1) from 1 to 60, do (Actions)
        • Loop - Actions
          • Wait 0.10 seconds
          • Set Degrees = (Degrees - 6.00)
          • Unit - Create 1 Dummy for (Owner of Caster) at (Point offset by 750.00 towards Degrees degrees) facing Default building facing degrees
          • Hashtable - Save Handle Of(Last created unit) as (Key dummy) of 0 in Hash
          • Unit - Add Clock Lightning to (Load (Key dummy) of 0 in Hash)
          • Unit - Order (Load (Key dummy) of 0 in Hash) to Orc Far Seer - Chain Lightning (Load (Key dummy) of 1 in Hash)
          • Wait 0.10 seconds
          • Unit - Create 1 Dummy for (Owner of Caster) at (Point offset by 750.00 towards Degrees degrees) facing Default building facing degrees
          • Hashtable - Save Handle Of(Last created unit) as (Key dummy) of 1 in Hash
          • Unit - Add Clock Lightning to (Load (Key dummy) of 1 in Hash)
          • Unit - Order (Load (Key dummy) of 1 in Hash) to Orc Far Seer - Chain Lightning (Load (Key dummy) of 0 in Hash)
 
Last edited:
^That's not MUI.

  • Untitled Trigger 008
    • Events
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 10, do (Actions)
        • Loop - Actions
          • Set p1 = (Center of (Playable map area))
          • Unit - Create 1 Footman for Player 1 (Red) at p1 facing Default building facing degrees
          • Hashtable - Save Handle Of(Last created unit) as (Key (dummy + (String((Integer A))))) of (Key (Triggering unit)) in Hash
          • Custom script: call RemoveLocation(udg_p1)
The dummied will be saved with keys
dummy1
dummy2
...
dummy10

They will be keyed to the caster. So a new cast will overwrite the dummy keys. You can incorporate a cast counter into the key to prevent that. ButI recommend you clear the dummies before/once the new cast is made to prevent lag.

To create the key, select Hashtable - Get String Id -> Concatenate Strings -> write dummy in the first string,select convert integer to string for string 2, convert for loop index A.
 
Thanks guys, between both of your posts I got it working (sort of). Depending on the parameters you set, the spell will draw all sorts of stars, polygons, inscribed polygons, etc. Additionally, red lightning connects the verticies of the inner and figures in a sweeping pattern. The orb above the caster shoots lightning at enemies in range.

195349-albums4241-picture40139.jpg


It's MUI in the sense that it works if I give two units the spell and have them both use it at the same time. It's bugged and not MUI in the sense that it does not display properly if any given unit executes the spell more than once. Certain "links" are left out of the figure that is drawn. The dummies are being placed properly, and the damage part of the triggers is working fine, but I don't think I'm cleaning up the hashtable correctly. This is probably an issue for another thread... I just wanted to give a heads up.

195349-albums4241-picture40140.jpg
 
Status
Not open for further replies.
Back
Top