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

passing local variable in timers?

Status
Not open for further replies.
Level 2
Joined
Jan 30, 2006
Messages
12
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.
 
Level 11
Joined
Jul 20, 2004
Messages
2,760
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!

~Daelin
 
Level 2
Joined
Jan 30, 2006
Messages
12
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?
 
Level 2
Joined
Jan 30, 2006
Messages
12
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?
 
Level 11
Joined
Jul 20, 2004
Messages
2,760
Change the function like this:

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!

~Daelin
 
Status
Not open for further replies.
Top