TriggerHappy
...
- Reaction score
- 341
GetWidgetType
TriggerHappy187
TriggerHappy187
Script Info
This function can detect what type of widget a widget is.
Widgets can be either an unit,item or destructable.
You also may ask why it returns an integer, well this is the easiest way I could think of to detect what type the widget is, by representing a different integer for each different widget type.
- JASS:
constant integer WIDGET_TYPE_ITEM
- JASS:
constant integer WIDGET_TYPE_UNIT
- JASS:
constant integer WIDGET_TYPE_DESTRUCTABLE
If you still don't understand on how you would use those constants, here is an example.
JASS:
scope example initializer InitTrig
private function Actions takes nothing returns nothing
local widget u = CreateUnit(Player(0), 039;hfoo039;, 0, 0, 0)
local widget i = CreateItem(039;ratf039;, 0, 0)
local widget d = CreateDestructable(039;ATtr039;, 0, 0, 0, 0, 1)
if GetWidgetType(u) == WIDGET_TYPE_UNIT then
call BJDebugMsg("u is a unit")
endif
if GetWidgetType(i) == WIDGET_TYPE_ITEM then
call BJDebugMsg("i is an item")
endif
if GetWidgetType(d) == WIDGET_TYPE_DESTRUCTABLE then
call BJDebugMsg("d is an Destructable")
endif
endfunction
//===========================================================================
private function InitTrig takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterTimerEvent( t, 0.00, false)
call TriggerAddAction( t, function Actions )
endfunction
endscope
The Script
JASS:
library GetWidgetType
globals
constant integer WIDGET_TYPE_ITEM = 0
constant integer WIDGET_TYPE_UNIT = 1
constant integer WIDGET_TYPE_DESTRUCTABLE = 2
endglobals
//! textmacro GetWidgetType takes TYPE,TYPECAST
private function $TYPECAST$ takes widget w returns $TYPE$
return w
return null
endfunction
//! endtextmacro
//! runtextmacro GetWidgetType("unit","W2U")
//! runtextmacro GetWidgetType("destructable","W2D")
//! runtextmacro GetWidgetType("item","W2I")
function GetWidgetType takes widget w returns integer
if GetUnitTypeId(W2U(w)) != 0 then
return WIDGET_TYPE_UNIT
elseif GetDestructableTypeId(W2D(w)) != 0 then
return WIDGET_TYPE_DESTRUCTABLE
elseif GetItemTypeId(W2I(w)) != 0 then
return WIDGET_TYPE_ITEM
endif
return -1
endfunction
endlibrary