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

[General] Using Hashtables for Trigger Names

Status
Not open for further replies.
Level 4
Joined
Jun 28, 2010
Messages
38
Welp, I'm stumped, this is the first time I've tried using a hashtable but it seemed fairly straight forward. What I want to do is create a hashtable that stores the names of triggers so that I can assign said names to a trigger variable for use in registering a custom event to a trigger.

  • Add Events to Buttons
    • Events
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • For each (Integer loop) from 0 to 7, do (Actions)
        • Loop - Actions
          • Hashtable - Save (gg_trg_Adjust_Cam_Slow_ + (String((loop + 1)))) as 0 of 0 in (Last created hashtable).
          • Set VariableSet triggerName = (Load 0 of 0 in (Last created hashtable).)
          • Custom script: call BlzTriggerRegisterFrameEvent(udg_triggerName, but[udg_loop], FRAMEEVENT_MOUSE_ENTER)
      • Set VariableSet loop = 0
      • For each (Integer loop) from 0 to 11, do (Actions)
        • Loop - Actions
          • Hashtable - Save (gg_trg_Adjust_Cam_Medium_ + (String((loop + 1)))) as 0 of 0 in (Last created hashtable).
          • Set VariableSet triggerName = (Load 0 of 0 in (Last created hashtable).)
          • Custom script: call BlzTriggerRegisterFrameEvent(udg_triggerName, butRam[udg_loop], FRAMEEVENT_MOUSE_ENTER)
      • Set VariableSet loop = 0
      • For each (Integer loop) from 0 to 15, do (Actions)
        • Loop - Actions
          • Hashtable - Save (gg_trg_Adjust_Cam_Fast_ + (String((loop + 1)))) as 0 of 0 in (Last created hashtable).
          • Set VariableSet triggerName = (Load 0 of 0 in (Last created hashtable).)
          • Custom script: call BlzTriggerRegisterFrameEvent(udg_triggerName, butThird[udg_loop], FRAMEEVENT_MOUSE_ENTER)
The logic seems right? In my mind its doing the following:

1. Create Hashtable
2. Save string in hashtable "gg_trg_Adjust_Cam_Slow_" + toString(loop + 1)
3. Set triggerName = hashvalue 0 of 0
4. Run my custom script where it registers the event to the trigger using triggerName as the name of the trigger.

Then it just loops for all that I need it for.
 

Attachments

  • test.w3m
    449.6 KB · Views: 13

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
You are trying to load a hashtable storage location containing a string as a trigger object. Fortunately hashtables are robust enough to detect this so instead return null.

Triggers do not have a name to refer to, they are passed around by reference. I am not sure what you want to do is possible. Instead I recommend making the triggers as generic as possible so the same trigger can process input from all players.
 
Status
Not open for further replies.
Top