GetWidgetLife(GetTriggerUnit())
works but GetUnitState(GetTriggerWidget(), UNIT_STATE_LIFE)
shouldn't work.I am still trying to look into which is faster but I can not locate the compiled trigger script in the memory of WC3. Once I find that I can give proof as to which is faster and why.
globals
hashtable blah = InitHashtable()
endglobals
function W2U takes widget w returns unit
call SaveWidgetHandle(blah,0,0,w)
return LoadUnitHandle(blah,0,0)
endfunction
GetTriggerUnit()
returned faster.library Benchmark initializer OnInit
native StopWatchCreate takes nothing returns integer
native StopWatchMark takes integer stopwatch returns real
native StopWatchDestroy takes integer stopwatch returns nothing
globals
private constant string TITLE_A="GetTriggerUnit() "
//! textmacro Benchmark__TestA
call GetTriggerUnit()
//! endtextmacro
private constant string TITLE_B="GetTriggerWidget() "
//! textmacro Benchmark__TestB
call GetTriggerWidget()
//! endtextmacro
endglobals
private function TestA1000 takes nothing returns nothing
local integer i=100
loop
exitwhen i==0
set i=i-1
//! runtextmacro Benchmark__TestA() // 1
//! runtextmacro Benchmark__TestA() // 2
//! runtextmacro Benchmark__TestA() // 3
//! runtextmacro Benchmark__TestA() // 4
//! runtextmacro Benchmark__TestA() // 5
//! runtextmacro Benchmark__TestA() // 6
//! runtextmacro Benchmark__TestA() // 7
//! runtextmacro Benchmark__TestA() // 8
//! runtextmacro Benchmark__TestA() // 9
//! runtextmacro Benchmark__TestA() // 10
endloop
endfunction
private function TestB1000 takes nothing returns nothing
local integer i=100
loop
exitwhen i==0
set i=i-1
//! runtextmacro Benchmark__TestB() // 1
//! runtextmacro Benchmark__TestB() // 2
//! runtextmacro Benchmark__TestB() // 3
//! runtextmacro Benchmark__TestB() // 4
//! runtextmacro Benchmark__TestB() // 5
//! runtextmacro Benchmark__TestB() // 6
//! runtextmacro Benchmark__TestB() // 7
//! runtextmacro Benchmark__TestB() // 8
//! runtextmacro Benchmark__TestB() // 9
//! runtextmacro Benchmark__TestB() // 10
endloop
endfunction
private function OnEsc takes nothing returns nothing
local integer sw
local integer i
set i=0
set sw=StopWatchCreate()
loop
set i=i+1
call TestA1000.evaluate()
exitwhen i==10
endloop
call BJDebugMsg("|cff66ddff"+TITLE_A+" : "+R2S(StopWatchMark(sw)*100)+"|r")
call StopWatchDestroy(sw)
set i=0
set sw=StopWatchCreate()
loop
set i=i+1
call TestB1000.evaluate()
exitwhen i==10
endloop
call BJDebugMsg("|cffddff66"+TITLE_B+" : "+R2S(StopWatchMark(sw)*100)+"|r")
call StopWatchDestroy(sw)
endfunction
private function OnInit takes nothing returns nothing
local trigger t=CreateTrigger()
call TriggerRegisterPlayerEvent(t,Player(0),EVENT_PLAYER_END_CINEMATIC)
call TriggerAddAction(t,function OnEsc)
endfunction
endlibrary