• Check out the results of the Techtree Contest #19!
  • 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.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

Mini-system for destroying effects with a delay

Level 6
Joined
Jul 3, 2006
Messages
102
I am trying to develop a small system to handle effect delayed destruction using a hashtable.
What I am doing:
  • Store each effect's timeout at the key of its handle.
  • Have a timer looping through all registered effects decrementing the timeout.
  • Each effect that reaches the timeout is destroyed and removed from the hashtable.

Where I am stuck:
How can I keep a list of all alive effects? An array seems logical, but it would be hard to manage the effect indices correctly. Is there a way I am missing?
Is there a way to get all active hashtable keys for example?
 
Where I am stuck:
How can I keep a list of all alive effects? An array seems logical, but it would be hard to manage the effect indices correctly. Is there a way I am missing?
Is there a way to get all active hashtable keys for example?
I have such a system, but I use vjass and I use one timer per effect. Could do it better today, but I made it quite a while ago.

1. There is no way to list all alive effects, you'd need to add it to some data-storage (array or hashtable) when it's relevant to keep track of.
2. There is no way to get all active hashtable keys or sub-keys. In order to do that you'd need something like [Lua][vJass] New Table (extremely useful!). Only downside is that you'd need a lot of custom script if you use GUI (I like it though).



Continue it with HashTable:

Create a effectIndexMax-variable (or save it in the HashTable at a predetermined location, such as 0,0)
Save index -> handleId in the hashtable (Something like: Save Integer into 0, index -> handle where handle is the handle of effect, same as you use for timeout)
In order to iterate through them all, you can do a for loop up to effectIndexMax to and use the new index-to-handle to get all the handles.
When something gets deleted, you'd also need to swap the index of the last handleId saved with the index of the deleted effect.


Doing it with array:
Using 1 array for effects, 1 array for remaining duration, 1 timer-variable and 1 integer for keeping track of last index (or "size" is one common way of doing similar things). Let last index start as -1, when adding do +1 and add it there. If last index is 0, you have something and can start your timer (otherwise your timer is does nothing).
When 1 effect ends, destroy it and swap the last index to the current index, lower the last index by 1 and DON'T increment the current index (or do currentIndex - 1), because you have not run the check for the instance moved to "currentIndex".
Of course you'd need an end-of-array check before the next loop iteration to handle destroying the last element in the array.

For a longer explanation with a different scenario than yours, see: Visualize: Dynamic Indexing
 
Back
Top