HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

[JASS] Checking if a unit is dead

09-09-2009, 05:47 PM#1
Element of Water
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.
Expand JASS:
I thought this point needed to be brought to the community's attention, especially the spell moderators who always say that you need to check GetWidgetLife with 0.405.
09-09-2009, 05:59 PM#2
Tot
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
Rising_Dusk
Quote:
Originally Posted by Element of Water
I thought this point needed to be brought to the community's attention
Everyone already knows this. It's been known for years at this point. The thing is that if you code your map properly, you'll never run into an issue with this. If you're so worried about it, go ahead and create an IsUnitDead function like:
Collapse JASS:
function IsUnitDead takes unit u returns boolean
    return IsUnitType(u, UNIT_TYPE_DEAD) or GetUnitTypeId(u) == 0
endfunction
The latter checks if the unit exists anymore, and it is proper behavior for IsUnitDead to return false on removed units anyways. The rest is hopefully obvious. Of course, if you code your map properly anyways, you will probably already have an IsUnitDead/IsUnitAlive function, and if you encounter some bug with GetWidgetLife you can always swap to the other version. It's no big deal either way.
09-09-2009, 06:36 PM#4
Element of Water
Quote:
Originally Posted by Pyrogasm
Cool, but just take a screenshot of the email/PM or whatever and put it in your first post so nobody bugs you about it.

Also, your testmap is called "Magnetism", when it should say "Gravity Ball", and ingame it is still "Just Another Warcraft III Map".
  • Maybe it's just something with your testmap or whatever, but the spell doesn't grant credit/gold for kills, though the hero does gain experience...
  • You could use a linked list of PullUnits in the Data struct instead of an array and remove the need for the MAX_UNITS constant and a limitation in max instances/units affected.
  • PolarProjectionX/Y will get inlined, I know... but isn't it a little stupid to have them out like that?
  • A unit doesn't die at 0 life; it dies at 0.405 life, so your check GetWidgetLife(u) > 0 should actually check > 0.405
  • The damagetype, attacktype, and weapontype used in the UnitDamageTarget calls should be configurable.
Aside from that, it seems rather optimized and well-written. I'd approve this if you change what I mentioned above and nobody else with more authority than I has anything to say against it.
Pyrogasm doesn't seem to be aware of it...
09-09-2009, 06:41 PM#5
Rising_Dusk
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
Element of Water
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
Rising_Dusk
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
Bobo_The_Kodo
Quote:
Originally Posted by Element of Water
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.
Quote:
Originally Posted by Pyrogasm
Find me a post and a testmap that a unit dies at 0, not 0.405. The opposite has already been proven in the past, so if there is new information that's come to light I'd like to see it.
You're wrong
09-09-2009, 11:17 PM#9
cosmicat
Quote:
Originally Posted by Tot
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
Surround a word in ## to highlight red and @@ to highlight yellow. However, this is overridden by syntax highlighting for strings.

"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
Master_of_Ra
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
cosmicat
Quote:
Originally Posted by Rising_Dusk
Collapse JASS:
function IsUnitDead takes unit u returns boolean
    return IsUnitType(u, UNIT_TYPE_DEAD) or GetUnitTypeId(u) == 0
endfunction
09-10-2009, 11:30 AM#12
Tot
Quote:
Originally Posted by cosmicat
Surround a word in ## to highlight red and @@ to highlight yellow. However, this is overridden by syntax highlighting for strings.

"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.

Got it working THANKS ,MAN
@@ yellow seems to be white...but still cool
09-10-2009, 03:12 PM#13
Pyrogasm
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.