[JASS] Blizzard Surprising Us: IF FALSE

Status
Not open for further replies.
Level 5
Joined
Dec 12, 2011
Messages
116
Hey guys, I found something really weird and buggy today, that took me one hour to reduce until I got to this.

So, let me explain to you wtf is going on.

(The test map is attached)

I have two triggers:

  • Init Trigger
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Custom script: if false then
      • -------- DISABLE THE FOLLOWING ACTION BEFORE TESTING!!! --------
      • Set u = Paladin 0000 <gen>
      • Custom script: endif
  • Test Trigger
    • Events
      • Player - Player 1 (Red) types a chat message containing test as An exact match
    • Conditions
    • Actions
      • Custom script: call BlizzardSurprisesMe( )
And the JASS function:

JASS:
function BlizzardSurprisesMe takes nothing returns nothing
    local region rectRegion = CreateRegion()

    call RegionAddRect(rectRegion, gg_rct_Region_000)
    if IsUnitInRegion(rectRegion, gg_unit_Hpal_0000) then
        call BJDebugMsg("Msg 1")
    else
        call BJDebugMsg("Msg 2")
    endif

    if RectContainsUnit( gg_rct_Region_000, gg_unit_Hpal_0000 ) then
        call BJDebugMsg("Msg 3")
    else
        call BJDebugMsg("Msg 4")
    endif
    call BJDebugMsg(" Surprised? Receiving only 2 and 3 no matter what? Oh!")
endfunction

Well, the fact is: This way everything works perfectly. The messages are displayed properly.

BUT, try disabling the "Set u = Paladin 0000 <gen>" action. Yes, disabling. It could be deleting as well, but you can just disable it to see what happens. And yes, when it's enabled, you still keep the "if false" thing.

Disable it and test the map again.

Wherever the unit is, the displayed messages will be 2 and 3!!! WTF!!
Putting something inside an "if false" statement, getting different results? WTF guys?



Could anyone think in something about this?

Since today, I will always set my preplaced units to dummy variables inside an "if false" statement. Or, better, I will never use generated variables anymore.


If you couldn't recreate the bug, tell me.
Tell me everything. I'm really interested on this.

EDIT: changed test map. now it's ok.
 

Attachments

  • RectRegionBugTest.w3x
    16.9 KB · Views: 64
Last edited:
Level 17
Joined
Apr 27, 2008
Messages
2,455
It's since years i used pre-placed units but i know that gg variables are created only once you've selected the preplaced thing on the map through a GUI action.
Once it's done i think you can disable or even delete this GUI action.
However i could be wrong but that doesn't make sense.

Now, about the message "1" and "3" displayed, that would make sense if gg_unit_Hpal_0000 == null and the point (0,0) is inside the rect gg_rct_Region_000.

Improve the debug, display the id of the gg variables (GetHandleId).

Or better, check the map script and share to us.
 
If there is no GUI function referencing a particular generated global, it will default null. (or at least for widgets) If there is a GUI function referencing it, then it will assign the generated global to the unit it is supposed to.

So in your case, if you disable it the global will return null. If you enable it, the global will return the actual unit. Well, that still leaves the question of why one condition returns that he is in the region and one doesn't.

IsUnitInRegion is a native, and I assume that it has a built-in check to see if the input is null. If the input is null, it will return false.

RectContainsUnit is a BJ, and it runs the function RectContainsCoords. The difference is that it checks if the unit's x and y coordinates are within the rect. When a null unit is referenced for GetUnitX and GetUnitY, it will return 0. Since the rect happens to contain the point (0, 0), that condition returns true. Note that if you move the rect so that it doesn't contain that point, the condition will return false.

Hope this clears the situation up. :)

EDIT: Troll_Brain beat me to the post.
 
Level 5
Joined
Dec 12, 2011
Messages
116
Yep, thank you very much guys, you already received +rep for that.

BTW, Troll Brain: I didn't got the point of viewing the HandleId of the variables. What's the idea?
 
Status
Not open for further replies.
Top