IsUnitType

Lightstalker

New Member
Reaction score
55
JASS:
IsUnitType(whichUnit, unitype whichUnitType)


I used:

JASS:
IsUnitType(u, ARMORY)


(ARMORY is an integer variable.)

but get the error: "Cannot convert integer to unittype."

I thought unit-types were integers:confused:

Also, I heard I shouldn't use IsUnitType but something else but can't remember what... :(
 

Azlier

Old World Ghost
Reaction score
461
if GetUnitTypeId(MyUnit) == ARMORY then...

You use IsUnitType for use with UNIT_TYPE_HERO(?) and such.
 

Tom Jones

N/A
Reaction score
437
IsUnitType(...) returns a "different" boolean than other functions that returns boolean, and because of this you should always compare the return to either true or false:
JASS:
if IsUnitType(...) == true or IsUnitType(...) == false


And yes, unit type constants are integers however they are still handles and are thusly protected from typecasting. You can however use ConverUnitType(...) to typecast your integer to a unit type, just don't expect any functions taking a unit type to work with it.

*Edit*
JASS:
if IsUnitType(...,ConvertUnitType(999)) == true then //This shouldn't work.
    ...
endif

//The below should work.
globals
    unittype MY_CUSTOM_UNIT_TYPE = ConvertUnitType(999)
endglobals

function ... takes unit u, unittype theType returns nothing
    if theType == UNIT_TYPE_RANGED_ATTACKER then
        ...
    elseif theType == UNIT_TYPE_HERO then
        ...
    elseif theType == MY_CUSTOM_UNIT_TYPE then
        ...
    endif
endfunction
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
IsUnitType(...) returns a "different" boolean than other functions that returns boolean, and because of this you should always compare the return to either true or false:

This is actually only true when using them for boolexpr. It's a combined problem with IsUnitType, with UNIT_TYPE_STRUCTURE (BUILDING?), while inside boolexpr.

Using a direct comparison uses a value of 0 as false, and any other value as true. Inside a boolexpr, a value of 1 returns true, and any other value is considered to be false. This isn't a problem with normal conditions, and the bug is only when using the IsUnitType function with UNIT_TYPE_STRUCTURE, which can return '64'.

Source: http://wiki.thehelper.net/wc3/IsUnitType#Bugs

As for the original poster, see Azlier's post. He posted the answer to your question.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
This is actually only true when using them for boolexpr. It's a combined problem with IsUnitType, with UNIT_TYPE_STRUCTURE (BUILDING?), while inside boolexpr.

Using a direct comparison uses a value of 0 as false, and any other value as true. Inside a boolexpr, a value of 1 returns true, and any other value is considered to be false. This isn't a problem with normal conditions, and the bug is only when using the IsUnitType function with UNIT_TYPE_STRUCTURE, which can return '64'.

Source: http://wiki.thehelper.net/wc3/IsUnitType#Bugs

As for the original poster, see Azlier's post. He posted the answer to your question.

JASS:
library IsUnitTypeBug initializer bug

globals
    private constant unittype WHICH_UNITTYPE = UNIT_TYPE_STRUCTURE
    private constant integer VALID_UNITID = 'htow' //townhall
    private constant integer INVALID_UNITID = 'hfoo' //footman
endglobals

private function Conditions1 takes nothing returns boolean
    return IsUnitType(CreateUnit(Player(0),VALID_UNITID,0.,0.,0.),WHICH_UNITTYPE)
endfunction

private function ExecutedOrNot1 takes nothing returns nothing
    call BJDebugMsg("test 1 valid")
endfunction

private function Conditions2 takes nothing returns boolean
    return not IsUnitType(CreateUnit(Player(0),INVALID_UNITID,0.,0.,0.),WHICH_UNITTYPE)
endfunction

private function ExecutedOrNot2 takes nothing returns nothing
    call BJDebugMsg("test 2 valid")
endfunction

private function bug takes nothing returns nothing
    local trigger bug1 = CreateTrigger()
    local trigger bug2 = CreateTrigger()
    
    call TriggerRegisterPlayerEventEndCinematic(bug1,Player(0))
    call TriggerAddCondition(bug1, Condition(function Conditions1))
    call TriggerAddAction(bug1,function ExecutedOrNot1)
    
    call TriggerRegisterPlayerEventEndCinematic(bug2,Player(0))
    call TriggerAddCondition(bug1, Condition(function Conditions2))
    call TriggerAddAction(bug1,function ExecutedOrNot2)
    
    if TriggerEvaluate(bug1) then
        call TriggerExecute(bug1)
    endif
    
    if TriggerEvaluate(bug2) then
        call TriggerExecute(bug2)
    endif
endfunction

endlibrary


It works as it should for me, so it can randomly fail, or is it fixed ?
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top