Looping a hashtable check

Status
Not open for further replies.
Level 8
Joined
Jul 29, 2010
Messages
319
I basically want this trigger to continue to loop to check whether the unit in question is dead and if so then save the new unit in the position of the dead unit, if not then increase the integer and save the new unit in a different position in the hashtable, just wondering if there is a more effective way of doing this?
  • Ability being cast
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
    • Actions
      • Set TargetUnit = (Target unit of ability being cast)
      • Set CastUnit = (Casting unit)
      • Set CustomValue = (CustomValue + 1)
      • Hashtable - Save Handle OfTargetUnit as CustomValue of CustomValue in Targets_Hashtable
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Load CustomValue of CustomValue in Casters_Hashtable) is dead) Equal to True
        • Then - Actions
          • Hashtable - Save Handle OfCastUnit as CustomValue of CustomValue in Casters_Hashtable
        • Else - Actions
          • Trigger - Run Ability being cast <gen> (checking conditions)
 
Level 45
Joined
Feb 27, 2007
Messages
5,578
IMO what you should do depends on how often you want to check if its dead, what needs to happen when it is found dead, and why you can't use the Unit - A unit dies event as a starting point to catch the death.

Use "starts the effect of an ability" instead of "begins casting". The latter will fire the event even if the unit gets stunned mid-cast and it never actually happens, the former won't fire until spell success. This is in general a really bad way to loop because it will immediately run the trigger again and cause the game to freeze or hit the op limit and crash the thread. Without putting some sort of delay in your loop you will always run into that same problem, so you could just add Time - Wait 0.50 seconds right before Trigger - Run Ability being cast <gen> but that wouldn't really be ideal either. It's sloppy. Also your hashtable save/load method is... real weird, and probably won't actually work because of what you're doing with CustomValue. When saving stuff into hashtables usually your parent or child key is the "Get handle id" function in GUI, which shows up as something like (Key (Triggering Unit)) in the trigger editor. That allows you to use the units handle id later to get back the relevant data, since handle IDs never change while a unit exists.

The easiest way imo is to use groups.
  • Ability being cast
    • Events
      • Unit - A unit starts the effect of an ability
    • Conditions
      • (Ability being cast) equal to YourAbil
    • Actions
      • Set TargetUnit = (Target unit of ability being cast)
      • Set CastUnit = (Casting unit)
      • Unit Group - Add TargetUnit to DEAD_GROUP
  • Periodic
    • Events
      • Time - Every 0.50 seconds of game-time
    • Conditions
    • Actions
      • Unit Group - Pick all units in DEAD_GROUP and do (Actions)
        • Loop - Actions
          • Set TargetUnit = (Picked Unit)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (TargetUnit is dead) Equal to True
            • Then - Actions
              • Unit Group - Remove (TargetUnit) from DEAD_GROUP
              • -------- do whatever when it dies here --------
            • Else - Actions
              • -------- not dead yet --------
 
Last edited:
Level 8
Joined
Jul 29, 2010
Messages
319
IMO what you should do depends on how often you want to check if its dead, what needs to happen when it is found dead, and why you can't use the Unit - A unit dies event as a starting point to catch the death.

Use "starts the effect of an ability" instead of "begins casting". The latter will fire the event even if the unit gets stunned mid-cast and it never actually happens, the former won't fire until spell success. This is in general a really bad way to loop because it will immediately run the trigger again and cause the game to freeze or hit the op limit and crash the thread. Without putting some sort of delay in your loop you will always run into that same problem, so you could just add Time - Wait 0.50 seconds right before Trigger - Run Ability being cast <gen> but that wouldn't really be ideal either. It's sloppy. Also your hashtable save/load method is... real weird, and probably won't actually work because of what you're doing with CustomValue. When saving stuff into hashtables usually your parent or child key is the "Get handle id" function in GUI, which shows up as something like (Key (Triggering Unit)) in the trigger editor. That allows you to use the units handle id later to get back the relevant data, since handle IDs never change while a unit exists.

The easiest way imo is to use groups.
  • Ability being cast
    • Events
      • Unit - A unit starts the effect of an ability
    • Conditions
      • (Ability being cast) equal to YourAbil
    • Actions
      • Set TargetUnit = (Target unit of ability being cast)
      • Set CastUnit = (Casting unit)
      • Unit Group - Add TargetUnit to DEAD_GROUP
  • Periodic
    • Events
      • Time - Every 0.50 seconds of game-time
    • Conditions
    • Actions
      • Unit Group - Pick all units in DEAD_GROUP and do (Actions)
        • Loop - Actions
          • Set TargetUnit = (Picked Unit)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked Unit) is dead) Equal to True
            • Then - Actions
              • Unit Group - Remove (TargetUnit) from DEAD_GROUP
              • -------- do whatever when it dies here --------
            • Else - Actions
              • -------- not dead yet --------
Ah sorry about my use of the hashtables, I've been told by others the same thing about my other triggers in the past, tbh I'm not 100% sure on how to use half the functions in the editor, I haven't slept for 2 days so that probably also doesn't help. I'll give your method a go
 
Status
Not open for further replies.
Top