| 01-03-2007, 11:49 PM | #1 |
In almost every script, people replace this with: GetWidgetLife(u)>.305 It's obvious to me that a unit with less than .306 hp is dead, but why the replacing? Is this another of those "we hate BJ functions"-replaces, or does IsUnitAliveBJ not return the correct value under certain circumstances? |
| 01-03-2007, 11:56 PM | #2 |
JASS:constant unitstate UNIT_STATE_LIFE = ConvertUnitState(0) function IsUnitAliveBJ takes unit whichUnit returns boolean return not IsUnitDeadBJ(whichUnit) endfunction function IsUnitDeadBJ takes unit whichUnit returns boolean return GetUnitState(whichUnit, UNIT_STATE_LIFE) <= 0 endfunction From what I heard GetWidgetLife is faster than GetUnitState(unit, UNIT_STATE_LIFE). GetUnitState, requires 2 function calls while GetWidgetLife is only 1 function call. |
| 01-03-2007, 11:59 PM | #3 |
As far as I know, you should use IsUnitType(GetFilterUnit(), UNIT_TYPE_DEAD)==false. Yes, many use the above approach, but to my knowledge Diod made a convincing post showing how the only safe approach was different from what you mention above. (http://www.wc3campaigns.net/showthread.php?t=86968) I have not myself seen the reason for why people use GetWidgetLife. |
| 01-03-2007, 11:59 PM | #4 |
In WC3, a unit dies when it's life reaches 0.405, not 0. That is why we change the number as well. Also, GetWidgetLife(...) is shorter to type than GetUnitState(...) That's the only reason I use it. :P |
| 01-04-2007, 09:37 AM | #5 | |
Quote:
Interesting... so if I have a heal ability which forget to check if units are dead, I can actually have a corpse with hp>1? :P |
| 01-04-2007, 12:17 PM | #6 |
Actually IsUnitDead didn't seem to work much better than GetWidgetLife when I was making corpse explosion, in fact it seemed to just check for the unit's life. When the unit had negative hp and was alife it was still returning true. The ==false should only be needed on return value of functions that are used for boolexprs |
