HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

best way to know if an unitid is valid or not ?

08-03-2009, 07:12 PM#1
Troll-Brain
Because of this bug it isn't so easy.

Collapse JASS:
library IsUnitIdValid uses IsGameLoaded

globals
   private unit U
endglobals

function IsUnitIdValid takes integer i returns boolean
    if IsGameLoaded() then // ofc i plan to store the result, to avoid the creation of the unit all the time, when it was already checked
                           // but i'm waiting for hashtables available on the official patch
        set U = CreateUnit(Player(0),i,0.,0.,0.) // yeah i should use a dummy player and constants reals X/Y instead
        
        if GetWidgetLife(U) != 0 then
            call RemoveUnit(U)
            return true
        else
            return false
        endif
        
    else
    
        return UnitId2String(i) != null
    endif
endfunction

endlibrary

Better ideas ?

PS : I don't want to store a boolean manually for each unitid possible on the map

EDIT : In case you wonder what is the function IsGameLoaded :

Expand JASS:

EDIT 2 : It seems that IssueBuildOrderById() always returns true while the arguments are "valids" (existent unit and order).
I mean it returns true for any existent order, "move" for example ...
08-04-2009, 03:30 PM#2
Captain Griffen
Uses...?
08-04-2009, 03:33 PM#3
Opossum
what about
return GetObjectName(i) != ""
08-04-2009, 03:59 PM#4
Troll-Brain
Quote:
Originally Posted by Captain Griffen
Uses...?
To know if an order is a construct order or not.

Quote:
Originally Posted by Opossum
what about
return GetObjectName(i) != ""
Then you can't know if the order is a construct order or not.
Or at least it will return true if you make an error on the script, since unitid, itemid and so one ... doesn't exist really, they are just integer, an error is easy to make.
I would still prefer the unit creation.
08-04-2009, 04:56 PM#5
Troll-Brain
It seems that simply check if unit isn't null after the CreateUnit... works.
I don't think someone will find a better way, but if you have one, let me know it.