• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] IsUnitType Issue

Status
Not open for further replies.
Level 7
Joined
Apr 30, 2011
Messages
359
well . . . maybe this is the solution . . .

IsUnitType(whichUnit, UNIT_TYPE_DEAD) and whichUnit != null

other than this, i don't know . . . .
it seems that exploding units is removed . . .
 
Level 7
Joined
Apr 30, 2011
Messages
359
then, it can be the native that bug . . . .

on KillUnit(whicUnit)
before it gets killed normally, it checks whether the unit explode on dead or not . .
if it's true, then remove the unit and play the unit's 'Art - Special' special effect . . .
otherwise, kill it normally . . .

i'm just guessing :3
 
WTF.
Good Job Blizzard.

I'm going to test this more and come up with a solution.

edit

There's no problem.

JASS:
struct Test extends array

    private static unit tester = null

    private static method print takes string s returns nothing
        call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, s)
    endmethod
    
    private static method explode takes nothing returns nothing
        call SetUnitExploded(tester, true)
        call KillUnit(tester)
        if IsUnitType(tester, UNIT_TYPE_DEAD) then
            call print("Unit is Dead")
        else
            call print("Unit is Alive")
        endif
        call print(R2S(GetWidgetLife(tester)))
    endmethod


    private static method onInit takes nothing returns nothing
        set tester = CreateUnit(Player(0), 'hpea', 512, 512, 270)
        call TimerStart(CreateTimer(), 4, false, function thistype.explode)
    endmethod
    
endstruct

This displays:

Code:
Unit is Dead
0.000

Maybe you're checking for the wrong unit.
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
extends array makes the struct completely dependent on the user for setup and everything. The situations where it is useful is for having structs for things that there are only a constant amount of, such as players.

These guys use it nowadays to declare their own constructor algorithms which is really just a waste of time because they really don't save themselves anything. I don't suggest using it where it isn't necessary (like has been done above).
 
Mr_Bean987,

Berb had this problem in the Projectile library, where he was only using IsUnitType, UNIT_TYPE_DEAD.

Here's the thing:

If you do this: IsUnitType(null, UNIT_TYPE_DEAD), it will return FALSE.

It would have been smarter for Blizzard to create UNIT_TYPE_ALIVE instead of UNIT_TYPE_DEAD, but hey, hindsight is 20/20 and we were not on the dev team.

Therefore, you also need the check "GetUnitTypeId(unit) != 0". This will check if the unit has been removed.

The correct method for checking if a unit is alive is this: not IsUnitType(unit, UNIT_TYPE_DEAD) and GetUnitTypeId(unit) != 0

unit == null will not work because remember, handles are smart pointers so they remember the handle ID, which is why you need to null unused variables. unit == null will only work if the unit variable was never pointing to a unit or was previously nulled.
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
Well to be honest why are you using a struct period? You've got a global and a bunch of functions.

JASS:
scope SameThing initializer onInit

    globals
        private unit tester = null
    endglobals
        
        
    private function print takes string s returns nothing
        call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, s)
    endmethod
    
    private function explode takes nothing returns nothing
        call SetUnitExploded(tester, true)
        call KillUnit(tester)
        if IsUnitType(tester, UNIT_TYPE_DEAD) then
            call print("Unit is Dead")
        else
            call print("Unit is Alive")
        endif
        call print(R2S(GetWidgetLife(tester)))
    endmethod


    private function onInit takes nothing returns nothing
        set tester = CreateUnit(Player(0), 'hpea', 512, 512, 270)
        call TimerStart(CreateTimer(), 4, false, function thistype.explode)
    endmethod

endscope

There's no reason to use more complicated syntax structure than required. Look, you already confused one person. For what?
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
Random notes :

For debug messages, BJDebugMsg is enough (unless you want the text display for more than 60 s, which can happens sometimes with long and/or complicated debug messages).
However, the chatbox is your friend.

Aslo i would use DisplayTextFromPlayer instead of DisplayTextToPlayer, with a valid player, because GetLocalPlayer bugs with replays (always return the first human player, even if that's not that easy i'm too lazy for more explanations about it), and DisplayTextFromPlayer displays for all players, until the player argument is a valid one.
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
I'm not confused, I've just been wondering what extends array means. I've seen it a few times but have never known what it means. I understand the rest of the code that Mag posted.

I'm willing to bet that you would be smart enough to figure out what it means if it was being used properly. It quite literally means that the struct extends the functionality of an array.

Rather than having:
JASS:
struct Example
    static integer array someDataElement
endstruct
...
    set Example.someDataElement[0] = 5

You would have:
JASS:
struct Example extends array
    int someDataElement
endstruct
...
    set Example[0].someDataElement = 5

Functions the exact same. Instead of having the array index on the "someDataElement" though you put it on the struct type, identifying that type as an array.
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
The problem with checking life is that you can have a dead unit with more than 0.405, and not only by trigger actions, with some native abilities also.
Honestly i think we should have a native IsUnitAlive with a boolean argument which cares or not about units being resurrected.
I'm not saying it exists, and we can already have something like that using the undefend "hack".

Someone knows how the AI unit alive handles units which are being resurrected ?
 
I've just been wondering what extends array means
its all in the JassHelper...a simple explanation is that you can use other struct's members...

JASS:
struct A
   string shit
endstruct

struct B extends A
   static method create takes nothing returns thistype
      local thistype this = thistype.allocate()
      set .shit = "i shit on my pants" //can use
      return this
   endmethod
endstruct

other than that, I dunu why people made custom allocators as it consumes space, although its more efficient than the normal allocator...

I've used UNIT_TYPE_DEAD many times and it does not bugg, well, never tested it like mag does...
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
I don't think that is an issue here because he isn't using it in a boolean expression, he's using it in an if-statement. The issue explained by Vexorian was only the result of how boolean expressions evaluated the integer 64 typecasted to a boolean value.
 
Status
Not open for further replies.
Top