HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Another IsUnitType bug?

01-31-2009, 09:04 PM#1
StRoNgFoE_2000
Knew about the original bug of "IsUnitType(unit, type) == boolean" for a long time from post - Vex's bug discovery....

If lets say your map has two different units that use the same unit type, UNIT_TYPE_TOWN_HALL in this example, but you only want a condition to return true for one of them, and you use other means to filter out the other unit, and you try to single line your return code, then it will ignore your other filters and just return true, regardless of arrangement of code.

Example..

Collapse JASS:
// - Tracker is a global unit variable with array, so here we have two units.
// - Note that both Tracker units have town hall as a unit type classification, but we don't want them to trigger this function.

// But,  this returns true even if Tracker 1 or 2 is equal to the trigger unit.
function Condition takes nothing returns boolean
    return IsUnitType(GetTriggerUnit(), UNIT_TYPE_TOWNHALL) == true and GetTriggerUnit() != Tracker[1] or GetTriggerUnit() != Tracker[2]
endfunction

// As does this...
function Condition takes nothing returns boolean
    return GetTriggerUnit() != Tracker[1] or GetTriggerUnit() != Tracker[2] and IsUnitType(GetTriggerUnit(), UNIT_TYPE_TOWNHALL) == true
endfunction

Both functions return true everytime for ANY unit that is considered town hall. But the below function works perfectly, messy, but avoids this bug.

Collapse JASS:
function Condition takes nothing returns boolean
    local unit u = GetTriggerUnit()
    if u == Tracker[1] or u == Tracker[2] or u == Tracker[3] or (any other condition) then
        set u = null
        return false
    elseif IsUnitType(u, UNIT_TYPE_TOWNHALL) == true then
        set u = null
        return true
    endif
    set u = null
    return false    
endfunction

It could possibly be the use of using !=, but I've never had issues with it before so my assumption is the problem lies in IsUnitType.
01-31-2009, 09:08 PM#2
Captain Griffen
and and not and or / or and.
01-31-2009, 09:22 PM#3
StRoNgFoE_2000
Quote:
Originally Posted by Captain Griffen
and and not and or / or and.

I'm afraid I don't follow, unless you meant using not to reverse the output instead of != ...

Collapse JASS:
function Condition takes nothing returns boolean
    return IsUnitType(GetTriggerUnit(), UNIT_TYPE_TOWNHALL) == true and not(GetTriggerUnit() == Tracker[1]) or not(GetTriggerUnit() == Tracker[2])
endfunction

The outcome is the same, Tracker 1 and 2 still return true. And if you meant use all and's instead of or's, then that would mean the trigger unit would have to be both Tracker 1 and 2 to return false, and both units aren't the same unit in the index.

Collapse JASS:
function Condition takes nothing returns boolean
    return IsUnitType(GetTriggerUnit(), UNIT_TYPE_TOWNHALL) == true and not(GetUnitTypeId(GetTriggerUnit()) == 'h03A')
endfunction

Still returns true, even though it is the units ID, so the bug must lie in IsUnitType.

Edit: fixed a small error..
01-31-2009, 10:18 PM#4
Fireeye
he meant as following:
Collapse JASS:
function Condition takes nothing returns boolean
    return IsUnitType(GetTriggerUnit(), UNIT_TYPE_TOWNHALL) == true and GetTriggerUnit() != Tracker[1] and GetTriggerUnit() != Tracker[2]
endfunction
Replaced the or with and.
It will return true otherwise cause even if it is Tracker[1] the same unit propably won't be Tracker[2]