• 🏆 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!

Timer Arrays?

Status
Not open for further replies.
Level 3
Joined
Dec 19, 2013
Messages
32
  • Events
    • Time - Timer[1] expires
    • Time - Timer[2] expires
  • Conditions
  • Actions
    • Set TimerArrayNumber = ?
How do I get the value of the timer that just expired? Surely there has to be a way besides making an individual trigger for each timer?
 
Level 14
Joined
Jun 27, 2008
Messages
1,325
I'm not sure this is the best way.
But you could run a if/then/else loop

For each integer X to NumberOfTimersInYourArray
loop -
If -
Timer [integer x] = expiring timer
Then -
Set TimerArrayNumber = Integer X
Else -

That works if you only have a few timers. If you however have lots of timers this will get very slow, also its very uncomfortable to write. Attacking data to timers using hashtables is the cleaner solution.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
Linear search the array for the timer to get its position, or if you order the array by handle ID you can use a binary search.

Binary search = O(log2(n)) complexity.
Linear search = O(n) complexity.

You could also use a hashtable to map the index values to the timer handle IDs. This has O(1) complexity unless the hashtable is over loaded.
 
Level 17
Joined
Jul 17, 2011
Messages
1,864
you should use one timer for the map and an integer array which gets incremented every time the timer runs, if the timer runs 300 times per second and you want something done every 3 seconds for a specific unit and assuming your integer array always starts at 0 then whenever it equals 900 you should execute whatever action u want and then reset it to 0 again
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
you should use one timer for the map and an integer array which gets incremented every time the timer runs, if the timer runs 300 times per second and you want something done every 3 seconds for a specific unit and assuming your integer array always starts at 0 then whenever it equals 900 you should execute whatever action u want and then reset it to 0 again
That is more efficient in some cases, but slower in others. It is also harder to manage and maintain to some degree.

The case of the trigger above could be a map revive system. Each player has his own parallel timer which is used to control when revives occur and to produce a timer dialog. To prevent procedural coupling it is logical to have the same code run by many timers (a trigger, many timer events) but the problem he is having is determining a unique identifying number from the expired timer that is used in a map of sorts (such as player ID number).

I do not see how your recommended approach can be used to do this. Especially the timer dialog parts.
 
Status
Not open for further replies.
Top