| 09-09-2009, 05:47 PM | #1 |
Ok, I noticed many users on this site have a misconception about the value GetWidgetLife returns for a dead unit. Most people think it's anything between 0 and 0.405. WRONG. It's ALWAYS 0 (unless you set the unit's life via triggers after it died). It is true that when a unit's health becomes 0.405 or below it dies, but what people don't realise, is that it's actually set to 0, regardless of what health it actually died on. Here is a JASS code to prove it. JASS:scope Test initializer Init private function Actions takes nothing returns nothing local unit u = CreateUnit(Player(0), 'hpea', 0., 0., 0.) call SetWidgetLife(u, GetRandomReal(0., 0.405)) call BJDebugMsg("The peasant's life is " + R2S(GetWidgetLife(u))) set u = null endfunction private function Init takes nothing returns nothing local trigger t = CreateTrigger( ) call TriggerRegisterPlayerEventEndCinematic( t, Player(0) ) call TriggerAddAction( t, function Actions ) call BJDebugMsg("Press ESC to spawn a peasant and set its life to a random number between 0 and 0.405. Its actual life will be outputted") endfunction endscope |
| 09-09-2009, 05:59 PM | #2 |
call BJDebugMsg("Press ESC to spawn a peasant and set its life to a random number between 0 and 0.405. Its actual life will be outputted")
is outputted a real english word? rabähhh...how to make jass-code colored red?...rabähhh |
| 09-09-2009, 06:05 PM | #3 | |
Quote:
JASS:function IsUnitDead takes unit u returns boolean return IsUnitType(u, UNIT_TYPE_DEAD) or GetUnitTypeId(u) == 0 endfunction |
| 09-09-2009, 06:36 PM | #4 | |
Quote:
|
| 09-09-2009, 06:41 PM | #5 |
He is plenty aware of it, he is actually just telling you that GetWidgetLife(u) > 0 is wrong no matter what. Either use 0.405 or the method I posted above. We also do not enforce it in spell submissions. As far as the rules are concerned, it is not crucial to use a custom IsUnitDead or GetWidgetLife(u) <= 0.405 for any submission. It is similar to how the MyArray[GetHandleId(u)-MIN_HANDLE_ID] can bug if you go over 8192 handles in your map. We typically have users implement a MAX_SIZE parameter to their script that is able to be calibrated to deal with the potential issue. Similarly, if your map happens to be coded in a not-so-great manner and you heal dead units, then you can just replace the GetWidgetLife(u) <= 0.405 in your spells with a custom IsUnitDead(u). I would consider that part of spell or script "calibration" for use in a given map. Furthermore, a custom HealUnit function in your map would make the GetWidgetLife() never bug out at all. (Since you would obviously check if a unit is alive before healing it in the HealUnit function) Can you see now why we do not force users to use the alternate method? |
| 09-09-2009, 06:49 PM | #6 |
Read the posts after it. Pyrogasm is not aware of it. He asked for proof when I said health is set to 0 when a unit dies. He said he'd only approve my spell if I fixed those things, one of which was the dead check. |
| 09-09-2009, 06:50 PM | #7 |
Perhaps you should actually link to a thread then, or rather than take the thread off-topic, PM one to me. |
| 09-09-2009, 09:49 PM | #8 | ||
Quote:
Quote:
|
| 09-09-2009, 11:17 PM | #9 | |
Quote:
"This @is@ a #string#" won't work, but function foo takes nothing does something returns nothing will. // Also doesn't work in #comments#. For more less information, read the sticky. |
| 09-09-2009, 11:45 PM | #10 |
i would note, that a dead hero will not always have widgetlife that is less than .405, what can be done to correctly determine if its dead? |
| 09-09-2009, 11:54 PM | #11 | |
Quote:
|
| 09-10-2009, 11:30 AM | #12 | |
Quote:
Got it working THANKS ,MAN @@ yellow seems to be white...but still cool |
| 09-10-2009, 03:12 PM | #13 |
If I ever learned that GetWidgetLife() returned 0 after the unit had died, then I must have forgotten it at some point because I have always used 0.405 for safety's sake. Pardon me for not knowing everything. However, Rising_Dusk's point still stands. |
