HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Order ID Comparisons

12-04-2007, 07:49 PM#1
xombie
I was in the process of making a spell when I came across some sort of logical error in an if-statement. After further investigation, I got it to work, but I had to "go around" the bug (if it is a bug).

Collapse JASS:
if GetUnitCurrentOrder( <unit> ) != OrderId( <string> ) then
This returned true seemingly always. I put a BJDebugMsg in the if-statement to see what it was registering 'GetUnitCurrentOrder' as, though it was the same as <string> so it shouldn't have returned true in the first place.

Collapse JASS:
if OrderId2String( GetUnitCurrentOrder( <unit> ) ) != <string> then
As you can probably see, this is merely an inverse from the first if-statement, moving OrderId to the other side and changing it to OrderId2String. The comparison in this situation is exactly then same, yet the oucomes are different. Does anybody know why this is?
12-05-2007, 04:09 PM#2
Troll-Brain
GetUnitCurentOrder == 0 when the order was given.
Use this for be sure :
call BJDebugMsg ( I2S ( GetUnitCurrentOrder (<unit>) ) )
but it takes some time for give an immediate order if the unit has received a point or widget target , what a joke :p
I mean you can't order it immediatly after the event run.
If i need it i do that :
Collapse JASS:
function Trig_test_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit ()
    call PauseUnit( u,true )
    call IssueImmediateOrderById ( u , 851973 ) // if the unit has an immediate order it is "saved"
    call PauseUnit( u,false )
endfunction

//===========================================================================
function InitTrig_test takes nothing returns nothing
    set gg_trg_test = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_test, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_test, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER )
    call TriggerAddAction( gg_trg_test, function Trig_test_Actions )
endfunction

Instead of call IssueImmediateOrderById ( u , 851973 ) you can order to stop, but the others orders don't work, if you want an other you must order it after the unpause.

Ok it's not the subject but it's intersting, no ? ^^
12-05-2007, 04:30 PM#3
xombie
Please assume I'm not an idiot.

I debugged what the GetUnitCurrentOrder returned, converted it to a string, and it came out with "blizzard" (I did this before the if statement). What its basically telling me is this:

Collapse JASS:
call BJDebugMsg(OrderId2String(GetUnitCurrentOrder(<unit>)))
if (GetUnitCurrentOrder(<unit>) != OrderId("blizzard")) then
    call BJDebugMsg(OrderId2String(GetUnitCurrentOrder(<unit>)))
endif
Both of the 'BJDebugMsg' calls display the message "blizzard". You also fail to address the problem then of why this does work, because if what you say is true then my current method would not work:
Collapse JASS:
if (OrderId2String(GetUnitCurrentOrder(<unit>)) != "blizzard") then
...
endif
This works- if what you said was true then it would not, and this is obvious.

To add to that, this if-statement is called on a timer event, so it is not "immediately" after he is issued the order. Regardless, though, think the problem through before typing out the first thing that pops into your head. If you had even read my entire question I'm sure you could've figured it out.

** EDIT **

Sorry if I was rude. By the way,
Collapse JASS:
call BJDebugMsg( I2S( GetUnitCurrentOrder( <unit> ) )
- this will return the integer of the ID as a string. What you really want is "OrderId2String" to convert the integer to the name of the order, like "blizzard" or "stomp".

This is not the problem however. For some reason:
Collapse JASS:
GetUnitCurrentOrder(...) != OrderId(...)
This is not the same as:
Collapse JASS:
OrderId2String( GetUnitCurrentOrder(...) ) != <order string>
Where <order string> is what is in the first "OrderId" argument.

In more mathematical terms, this means that "Arctan(X) != Y" yet "Tan(Y) = X".
12-06-2007, 12:11 PM#4
Troll-Brain
yes you were rude but i have read the post really quickly, sorry.

strange i test it for "smart" and it works.

I assume you're not an idiot but i don't lie for the bug, just try it :

Collapse JASS:
function Trig_test_Actions takes nothing returns nothing
    call IssueImmediateOrderBJ( GetTriggerUnit(), "holdposition" )
    call BJDebugMsg ( "obey me ffs unit !")
endfunction

//===========================================================================
function InitTrig_test takes nothing returns nothing
    set gg_trg_test = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_test, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_test, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER )
    call TriggerAddAction( gg_trg_test, function Trig_test_Actions )
endfunction
12-06-2007, 10:06 PM#5
xombie
Yea I tested it all appropriately. The fact is he is under the order of "blizzard" yet for some reason it says he isn't. Somehow, this statement returns true even though it is not:

Collapse JASS:
if ( GetUnitCurrentOrder( <unit> ) != OrderId( "blizzard" ) ) then

Anybody can see that this would check if the unit's current order ID is the same as the order ID of "blizzard", basically, whether or not the unit is casting blizzard. To further check this, I do:

Collapse JASS:
if ( GetUnitCurrentOrder( <unit> ) != OrderId( "blizzard" ) ) then
    call BJDebugMsg( OrderId2String( GetUnitCurrentOrder( <unit> ) ) )
endif

Now, anybody initially looking at this code would think that the 'BJDebugMsg' would display anything but the text "blizzard", yet it still detects blizzard as being the unit's current order. It is, too. Blizzard is actually the unit's current order, though the if-statement for some reason doesn't recognize it.

Altering the if-statement to look like this:
Collapse JASS:
if ( OrderId2String( GetUnitCurrentOrder( <unit> ) ) != "blizzard" ) then

Now it works, even though I haven't changed the content of the if-statement at all, it is merely written a different way. In principle, I took the "OrderId" function from the right-hand-side and inversed it to the left-hand-side, for some reason this makes all the difference.
12-06-2007, 10:18 PM#6
xombie
Alright. I'm deleting the post. I don't know what exactly caused it but for some reason it works fine now.