HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Detecting if a widget is a unit

01-14-2009, 09:02 PM#1
PandaMine
Suppose that you have a widget w

local widget w
And it gets assigned to a widget

Is there a way to tell if the widget w is a unit as opposed to not a unit?
01-14-2009, 09:17 PM#2
PandaMine
dw, thanks to griffen's help you can just typecast the widget to a unit and use GetUnitTypeId to tell if its a unit or not
01-15-2009, 07:14 PM#3
Strilanc
GetUnitTypeId will return 0 if it's not a unit, or the unit has decayed.

Important difference sometimes.
01-15-2009, 07:26 PM#4
Captain Griffen
Quote:
Originally Posted by Strilanc
GetUnitTypeId will return 0 if it's not a unit, or the unit has decayed.

Important difference sometimes.

If it's decayed, it is no longer a unit; it was a unit, but now is not. It's nothing. It's a free index. Or possibly a leaked index. But it's not a unit.
01-15-2009, 08:31 PM#5
Strilanc
Quote:
Originally Posted by Captain Griffen
If it's decayed, it is no longer a unit; it was a unit, but now is not. It's nothing. It's a free index. Or possibly a leaked index. But it's not a unit.

Yes, but it used to be a unit and part of your map might still be treating it as a unit.

For example, consider an ability which has a different initial effect on destructables and units, then a common later effect. Suppose you want to cleanup that initial effect when the later effect happens. If you expected handles to hold their type, you might simply attach a widget to a timer and let the later call figure out what to cleanup using GetUnitTypeId. That's a leak or even a bug waiting to happen if the unit expires in the mean-time.

Contrived? A little. But it's important to know these types of weird details.

... Also PandaMine now knows he can use it to detect decay.