Unit's dying life point?

waaaks!

Zinctified
Reaction score
256
Each time I check if is a unit dead or not, I always used < 0.405 for checking dead units, and > 0.405 for checking alive units, while some coders use 0.406, so what is the right and accurate value to be used to check dead or alive units?
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
IsUnitType(whichUnit,UNIT_TYPE_DEAD).
This is faster than GetWidgetLife and more accurate.
However, the value is 0.403, so far I researched it.
 

Kenny

Back for now.
Reaction score
202
>IsUnitType(whichUnit,UNIT_TYPE_DEAD).
This is faster than GetWidgetLife and more accurate.

Since when? From what I've heard, [ljass]GetWidgetLife()[/ljass] is quite a fast native. And [ljass]IsUnitType()[/ljass] would only be more accurate if your coding is of poor quality.

Also, 0.403 seems a bit off. From most tests, it seems to be around 0.406 or so.
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Since when? From what I've heard, GetWidgetLife() is quite a fast native. And IsUnitType() would only be more accurate if your coding is of poor quality.
I benchmarked it. IsUnitType faster about 20%.
 

Azlier

Old World Ghost
Reaction score
461
I won't believe it without the benchmark script.
 

uberfoop

~=Admiral Stukov=~
Reaction score
177

Jesus4Lyf

Good Idea™
Reaction score
397
JASS:
scope S initializer Init
private function THE_TRUTH_ABOUT_LIFE_AND_DEATH takes nothing returns nothing
    local unit u = CreateUnit(Player(0),&#039;hfoo&#039;,0,0,0)
    call SetWidgetLife(u,.405)
    call SetWidgetLife(u,9001)
    if GetWidgetLife(u)==0 then
        call BJDebugMsg(&quot;!&quot;)
    endif
    if GetWidgetLife(u)&gt;9000 then
        call BJDebugMsg(&quot;IT&#039;S OVER 9000!&quot;)
    elseif GetWidgetLife(u)&gt;1 then
        call BJDebugMsg(&quot;Well, it&#039;s not 0.&quot;)
    endif
    if IsUnitType(u,UNIT_TYPE_DEAD) then
        call BJDebugMsg(&quot;The Footman is &#039;dead&#039;.&quot;)
    endif
    call UnitRemoveType(u,UNIT_TYPE_DEAD)
    if IsUnitType(u,UNIT_TYPE_DEAD) then
        call BJDebugMsg(&quot;The Footman is not &#039;dead&#039;.&quot;)
    endif
endfunction

private function Init takes nothing returns nothing
    call TimerStart(CreateTimer(),2,true,function THE_TRUTH_ABOUT_LIFE_AND_DEATH)
endfunction
endscope

Someone try?
If anyone thinks it unrealistic, remember that heals over time may exist...

Edit: The remove dead type is completely unrealistic. Let us know if the footman dies, and what displays.
 

uberfoop

~=Admiral Stukov=~
Reaction score
177
-The unit died
-'Well, it's not over 0' displayed (the health gets set to the unit's max, in this case 420)
-'The footman is 'dead'.' displayed
-'The footman is not 'dead'.' displayed; the type was properly removed




In other words, Blizzard is froodlenutzskying hilarious. Units die below ~.405 life, and their life gets set to zero on the spot, and it seems they receive a dead type. HOWEVER, you can manipulate the life after that anyway (based on prior life bounds for the unit), AND you can remove the dead type.

So none of these checks are theoretically completely safe.
 

Tom_Kazansky

--- wraith it ! ---
Reaction score
157
>If anyone thinks it unrealistic, remember that heals over time may exist...

for my heals over time spells, I always check if the unit is dead or not first :D
---
But I concern about the speed now

>I won't believe it without the benchmark script.

me too, even though I don't know much about benchmark :eek:
 

Jesus4Lyf

Good Idea™
Reaction score
397
>So none of these checks are theoretically completely safe.
Exactly my point. Which is why [LJASS]IsUnitType(unit,UNIT_TYPE_DEAD)[/LJASS] is the safest, because the user must intentionally remove the type to screw it up. A heal over time could mess with the unit's health, so I don't think it as appropriate.

I might run a benchmark on the issue as well for interest, but personally I'd say people shouldn't use this whole GetWidgetLife nonsense for checking if a unit is dead. It doesn't make much sense, compared to the type check, since health is much more likely to change than removing the UNIT_TYPE_DEAD status, I imagine.

So: Schrödinger's cat
JASS:
function SchrodingersCat takes nothing returns nothing
    local unit u=CreateUnit(Player(15),&#039;hfoo&#039;,0,0,0)
    call SetWidgetLife(u,0)
    call SetWidgetLife(u,9001)
    call UnitRemoveType(u,UNIT_TYPE_DEAD)
endfunction

The footman is both alive and dead.
You could check by issuing a stop order, to see if it is dead, probably. But is there any way to tell without interrupting the unit or something?
I suppose you could have a dummy unit try to issue an order to attack it, and see if it fails, or something... but then what about [LJASS]call ShowUnit(unit,false)[/LJASS]? :p

What a puzzle.
 

Kenny

Back for now.
Reaction score
202
>I might run a benchmark on the issue as well for interest, but personally I'd say people shouldn't use this whole GetWidgetLife nonsense for checking if a unit is dead. It doesn't make much sense.

I have always used [ljass]GetWidgetLife()[/ljass] and not once have I had a problem.

To me, the only way you would cause it to bug is if you don't pay attention when you are coding something.

Also...

[ljass]IsUnitType(unit,UNIT_TYPE_DEAD) == true[/ljass] returns false for non-existant units. Which could also be a problem...
 

Jesus4Lyf

Good Idea™
Reaction score
397
>IsUnitType(unit,UNIT_TYPE_DEAD) == true returns false for non-existant units. Which could also be a problem...
We're all doomed.
WC3 mapping is no longer possible, go home everyone. :p

>To me, the only way you would cause it to bug is if you don't pay attention when you are coding something.
I suppose you're right.
 

Kenny

Back for now.
Reaction score
202
I suppose you could use something like:

JASS:
function IsUnitDead takes unit u returns boolean
    return IsUnitType(u,UNIT_TYPE_DEAD) == true or GetUnitTypeId(u) == 0
endfunction


So if you do attempt to check if a non-existant unit is dead (which to me would be as common as increasing a dead units life) it will still return true as the unit will not have a unit type id. :)
 
General chit-chat
Help Users
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +1
  • V-SNES V-SNES:
    Happy Friday!

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top