Attachment Systems
From WarCraft3
What is attaching?
When you work with structs, you might have a local struct in your function. Example:
function myFunc takes nothing returns nothing
local data d = data.create()
set d.u = whichUnit
//...
endfunction
And want to pass it to another function, for example a timer callback. That's where attaching becomes handy; basically you 'attach' your local struct onto your timer, and in your callback function, you recieve it. Example:
function Callback takes nothing returns nothing
local data d = GetTimerData(GetExpiredTimer()
// Do something with d
endfunction
function Main takes nothing returns nothing
local data d = data.create()
set d.u = whichUnit
set d.t = CreateTimer()
call SetTimerData(d.t, d)
call TimerStart(d.t, 0.03, true, function Callback)
endfunction
So this example basically attaches the local struct to the timer and gets it in the Callback function, just like stated above. Hell yeah, it's that simple.
How do we use those attaching systems?
Those attaching systems are pretty easy to use; commonly used function names are "Set(xxx)Data" and "Get(xxx)Data", and in some attaching systems you need to call "Remove(xxx)Data" or "Clear(xxx)Data". (xxx is the type, such as timer, trigger, etc.) TimerUtils, for example, uses "SetTimerData(timer, data)" and "GetTimerData(timer)".
Other systems, such as ABC, have more functions - such as "Set/GetTriggerStructA/B/C", "Set/GetTimerStructA/B/C" "Set/GetDialogStructA/B/C", but you also need to clean the data when you're done using it.
If you're unsure what function names the attaching system you use uses, there's probably a documentation following, so check that out!