When creating a local timer and calling it, how do you call functions that take variables? Whenever I do something like this:
{
function second takes unit x, unit z returns nothing function code endfunction
function first takes nothing returns nothing local timer t local unit x local unit z set x = ABC set z = DEF set t = CreateTimer() call TimerStart(t, 0.10, true, function second(x,z)) call TriggerSleepAction(2.00) call DestroyTimer(t) set x = null set z = null endfunction
}
It gives me an error, "Expected '". Apparently it doesn't like me calling a function that takes parameters with a timer. Is there any way to do this? Thanks.
Function must not only be a procedure (return nothing) but a piece of code (so it can take no parameters). And so, when starting the timer it should be like this:
call TimerStart(t, 0.10, true, function second)
No parameters, no paranthesis. That's how you use functions as pieces of code. When using paranthesis, you automatically call the function, which is different from using it as code.
How can you transmit locals to it? By using Kattana's local handles system of course. Why? Because you can link a value to the timer, and then retreive it into the code function like this:
local timer t = GetExpiredTimer() local unit cast = GetHandleUnit(t, "cast")
This is just an example of course. However, that's the only way you can transmit locals from one thread to another. Cheers!
Ah, okay. So only functions that take nothing and return nothing can be called as code. Thanks for the reply. But can you tell me a little more about this local handles system? When (and how) do I attach the locals to the timer? And what does GetExpiredTimer() do?
Ah. That makes things clearer. With enough tinkering with handles, I shouldn't have any further problems with multi-instanceability. Appreciate your time, Daelin. One last question, though: how do I put the handle script you have linked into my map?
Edit: Nevermind, figured that out fairly quickly. But there seem to be a number of issues with the script. One being with the cache dealt with in the LocalVars function Any idea on how to fix those?
function LocalVars takes nothing returns gamecache if udg_cach == null then call FlushGameCache(InitGameCache("cach")) set udg_cach=InitGameCache("cach") endif return udg_cach endfunction
Create a global variable with the name cach, or give it whatever name you want, and replace cach in the script (referring to udg_cach of course) with its name. That should do it!