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

[General] Finding out which timer fired the trigger

Status
Not open for further replies.
Level 29
Joined
Sep 26, 2009
Messages
2,595
Hi,
does anyone know how to find out which countdown timer fired a trigger, when there are multiple timers in the event block?

e.g. something like this:
  • Events
    • Time - timer[1] expires
    • Time - timer[2] expires
    • Time - timer[3] expires
    • Time - timer[4] expires
Note, that checking their remaining time may not be the best, since they may expire at around the same time and not be used again for a while.

The only way I came up with would be using bool array for each timer, however I thought someone here may know a better way to find it out.
 
You could store the Index of timers into hashtable and then load the index when it expires:

  • Hashtabelle - Create a hashtable
  • Set HT = Last Creted Hashtable
  • Countdown Timer - Start Timer 1 ....
  • Hashtabelle - Save 1 as 0 of (Key (Last started timer)) in HT
  • Countdown Timer - Start Timer 2 ....
  • Hashtabelle - Save 2 as 0 of (Key (Last started timer)) in HT
  • Countdown Timer - Start Timer 3 ....
  • Hashtabelle - Save 3 as 0 of (Key (Last started timer)) in HT
  • Events
  • Countdown Timer - Timer 1 Expires
  • Countdown Timer - Timer 2 Expires
  • Countdown Timer - Timer 3 Expires
  • Actions
  • Set Index = (Load 0 of (Key (Expiring timer)) from )HT
(did not test it)
 
Level 29
Joined
Sep 26, 2009
Messages
2,595
Thanks for answers :thumbs_up:

..or you could use dummy units with timed life that acts as a timer and set them in different variables/arrays.

Just a thought.
I want to avoid using dummies for this, as I already use a lot of them throughout the game.


You could store the Index of timers into hashtable and then load the index when it expires:
That's a very nice idea. I tested it and it went successfully.


I used 3 triggers to test this theory. Since it works, I'll post it here for future references:
  • Untitled Trigger 001
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set TESTHASH = (Last created hashtable)
      • Custom script: set udg_handle = udg_TESTTIMER[1]
      • Hashtable - Save 1 as (Key ID) of (Key handle) in TESTHASH
      • Custom script: set udg_handle = udg_TESTTIMER[2]
      • Hashtable - Save 2 as (Key ID) of (Key handle) in TESTHASH
      • Custom script: set udg_handle = udg_TESTTIMER[3]
      • Hashtable - Save 3 as (Key ID) of (Key handle) in TESTHASH
      • Custom script: set udg_handle = udg_TESTTIMER[4]
      • Hashtable - Save 4 as (Key ID) of (Key handle) in TESTHASH
Since I didn't want to save the handle each time I started that timer, I saved them at map initialization.

The second trigger just started all 4 timers with random times and wrote what times it started them with.

  • Untitled Trigger 003
    • Events
      • Time - TESTTIMER[1] expires
      • Time - TESTTIMER[2] expires
      • Time - TESTTIMER[3] expires
      • Time - TESTTIMER[4] expires
    • Conditions
    • Actions
      • Set int1 = (Load (Key ID) of (Key (Expiring timer)) from TESTHASH)
      • Game - Display to (All players) the text: ///////////////////...
      • Game - Display to (All players) the text: (EXPIRED TIMER: Timer[ + ((String(int1)) + ]))
This wrote which timer has expired.


So far, I made 5 tests and all were successful, so I guess there was no problem with it.


+Rep for all.
 
Status
Not open for further replies.
Top