I have a function:
But I don't want to start a 2-nd timer for the actionFunc, I want everything to happen with only one timer.
Is there any way I can save the "actionFunc" code somehow, and then call it inside the SlideToUnitLoop?
JASS:
function SlideToUnitLoop takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer id = GetHandleId(t)
local unit c = LoadUnitHandle(udg_Table, id, 'unit')
local unit u = LoadUnitHandle(udg_Table, id, 'targ')
local real dist = LoadReal(udg_Table, id, 'dist')
local real x = GetUnitX(u)
local real y = GetUnitY(u)
local real xc = GetUnitX(c)
local real yc = GetUnitY(c)
local real h = y-yc
local real w = x-xc
local real a = Atan2(h,w)
if h*h+w*w <= 10000.00 or IsUnitDeadBJ(c) or IsUnitDeadBJ(u) then
call RecTimer(t)
else
call SetUnitX(c, xc + dist*Cos(a))
call SetUnitY(c, yc + dist*Sin(a))
endif
set t = null
set c = null
set u = null
endfunction
function SlideToUnit takes unit u, unit t, real speed, code actionFunc returns nothing
local timer t1 = GetFreeTimer()
local integer id1 = GetHandleId(t1)
local timer t2
local integer id2
if actionFunc != null then
set t2 = GetFreeTimer()
set id2 = GetHandleId(t2)
call SaveUnitHandle(udg_Table, id2, 'unit', u)
call SaveUnitHandle(udg_Table, id2, 'targ', t)
call SaveReal(udg_Table, id2, 'dist', speed*0.05)
call TimerStart( t2, 0.05, true, actionFunc )
set t2 = null
endif
call SaveUnitHandle(udg_Table, id1, 'unit', u)
call SaveUnitHandle(udg_Table, id1, 'targ', t)
call SaveReal(udg_Table, id1, 'dist', speed*0.05)
call TimerStart( t1, 0.05, true, function SlideToUnitLoop )
set t1 = null
set u = null
set t = null
endfunction
Is there any way I can save the "actionFunc" code somehow, and then call it inside the SlideToUnitLoop?
JASS:
private function Fade takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer id = GetHandleId(t)
local unit c = LoadUnitHandle(udg_Table, id, 'unit')
local unit u = LoadUnitHandle(udg_Table, id, 'targ')
local real dist = LoadReal(udg_Table, id, 'dist')
local real x = GetUnitX(u)
local real y = GetUnitY(u)
local real xc = GetUnitX(c)
local real yc = GetUnitY(c)
local real h = y-yc
local real w = x-xc
local integer i = GetPlayerId(GetOwningPlayer(u))
if IsUnitAliveBJ( u ) then
if h*h+w*w <= 10000.00 then
call RecTimer(t)
call ShowUnit( c , false )
call UnitRemoveAbility( u , 'A02J' )
if Current_Type[i] == 1 then
call UnitAddAbility( u , 'A02L' )
elseif Current_Type[i] == 2 then
call UnitAddAbility( u , 'A02K' )
elseif Current_Type[i] == 3 then
call UnitAddAbility( u , 'A02M' )
endif
set SEF_C[i] = SEF_C[i] + 1
set Current_Type[i] = 0
if SEF_C[i] < 3 then
call UnitAddAbility( u , 'A02J' )
else
call UnitAddAbility( u , 'A02N' )
endif
else
call SetUnitVertexColor(c, 255, 255, 255, (255*R2I(h*h+w*w)/250000)-10)
endif
else
call RecTimer(t)
endif
set t = null
set c = null
set u = null
endfunction
call SlideToUnit( u , c , 400.00 , function Fade)