How to transfer data in JASS using a timer?

Level 8
Joined
Apr 16, 2025
Messages
160
I've heard this is possible.


For example, I could create a trigger: "unit enters the map", and then do something like:



local unit u = GetTriggerUnit()
call TriggerSleepAction(15.0) // or PolledWait
call KillUnit(u)


But I've also heard that PolledWait/TriggerSleepAction is really bad — it can cause desyncs or even crash the game under heavy load — so everyone recommends using a timer instead. The problem is that timers usually require writing the triggered unit into a global variable (often with arrays), which feels rather clumsy.


I remember hearing that timers can "carry" local variables into the callback function (so you don’t need to store them globally or in a hashtable). In older versions of WC3 this was definitely possible, but maybe there’s some workaround in Reforged? From what I’ve read, though, this feature seems to have been removed or works differently in Reforged — unless someone knows otherwise.


Any tips would be appreciated!
 
Last edited:
The problem is that timers usually require writing the triggered unit into a global variable (often with arrays), which feels rather clumsy.
Only GUI users do this, JASS users always use hashtable. Of course it's clumsy because it's a terrible crutch.
I remember hearing that timers can "carry" local variables into the callback function (so you don’t need to store them globally or in a hashtable). In older versions of WC3 this was definitely possible, but maybe there’s some workaround in Reforged? From what I’ve read, though, this feature seems to have been removed or works differently in Reforged — unless someone knows otherwise.
This isn't possible in JASS.
Local timers from YDWE can automatically save and unload data in their callback functions, but they also use a hashtable.
Any convenient solutions are made exactly like that inside.
 
Adding onto what others have said.

You can use this vJass Table system (no idea if it's outdated) so you don't have to create a new Hashtable each time:
If you work only with GUI, there are similar systems you can find that don't require any code.

The general idea for "transferring data using timers" is this:

1. A newly created timer is automatically assigned a unique Integer id (often referred to as a handle). All Warcraft objects are stored and identified this way.
2. You use that id as the [index] in an Array. That Array can store any value that you want: Unit, Item, Integer, etc.
3. This creates a relationship between the timer and the value that you want to keep track of. So as long as you have access to the timer you will also have access to any Arrays that you previously paired with it.

However, Arrays are limited in size (max index of 32,768) and the unique Integer id's use large numbers which exceed that limitation. So instead you're forced to use a Hashtable which doesn't have this same limitation. But working with Hashtables can be annoying and messy, so a system like Table exists to ease that process by simplifying the workflow, automating it, and reducing repetition (1 Hashtable vs many).
 
Last edited:
Back
Top