I have few questions:
1) Is it better to do multiple "if" checks:
Or would it be better if I use a hashtable:
2) Is it better to start a seperate (not-repeating) timer for every unit:
Or would it be better to use 1 looping timer for all the units?:
And also, I feel that both of the ways can be efficient, but 1 is used for some cases, and the other - for other cases.
When do I want to use the 1-st and when do I want to use the 2-nd method?
1) Is it better to do multiple "if" checks:
JASS:
if udg_int == 'A000' then
call UnitAddAbility(u, 'A02B')
elseif udg_int == 'A001' then
call UnitAddAbility(u, 'A02G')
elseif udg_int == 'A004' then
call UnitAddAbility(u, 'A01Q')
elseif udg_int == 'A00A' then
call UnitAddAbility(u, 'A031')
endif
call UnitAddAbility(u, LoadInteger(Table, 'abil', udg_int))
2) Is it better to start a seperate (not-repeating) timer for every unit:
JASS:
function OnExpire takes nothign returns nothing
local timer t = GetExpiredTimer()
local unit u = LoadUnitHandle(Table, GetHandleId(t), 'unit')
call UnitRemoveAbility(u, 'A021')
call FlushChildHashtable(Table, GetHandleId(t))
call DestroyTimer(t)
set t = null
set u = null
endfunction
function First takes nothin returns nothing
// some stuff
call UnitAddAbility(u, 'A021')
call SaveUnitHandle(Table, GetHandleId(t), 'unit', u)
call TimerStart(t, 5, false, function OnExpire)
// clearing leaks
enefunction
Or would it be better to use 1 looping timer for all the units?:
JASS:
function OnExpire takes nothing returns nothing
local integer i = 1
loop
exitwhen i > udg_max
set udg_time[i] = udg_time[i] - 0.03125
if udg_time[i] <= 0 then
call UnitRemoveAbility(udg_unit[i], 'A021')
set udg_time[i] = udg_time[udg_max]
set udg_unit[i] = udg_unit[udg_max]
set udg_max = udg_max - 1
else
set i = i + 1
endif
endloop
if udg_max == 0 then
call DestroyTimer(GetExpiredTimer())
endif
endfunction
function First takes nothing returns nothing
//some actions
if udg_max == 0 then
set t = CreateTimer()
call TimerStart(t, 0.03125, true, function OnExpire)
endif
set udg_max = udg_max + 1
set udg_unit[udg_max] = u
set udg_time[udg_max] = 5
//leak clearing
endfunction
And also, I feel that both of the ways can be efficient, but 1 is used for some cases, and the other - for other cases.
When do I want to use the 1-st and when do I want to use the 2-nd method?