HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

TriggerRegisterEnterRegion

02-17-2007, 11:11 PM#1
Omnikron13
Hey, I've been learning JASS recently, and when looking through the JASS manual for a unit enters region event, I found TriggerRegisterEnterRegion, which seems to be what I want, but I'm puzzled about for a couple of reasons.
I apologise if this seems very dumb for the experienced JASS programmers out there.

Firstly, it takes the type region, instead of the type rect, which seems to be used much more often, why is this?

Secondly, I'm not sure how the 'boolexpr filter' part works, is anyone able to explain this to me?

I have looked to the source of the function used by GUI in the JASS manual, and can see how it is doing things, but it is called 'simple' and I'm guessing lacks the power of the native, but I'm using it for now.

Thanks.
02-18-2007, 07:01 AM#2
Chocobo
Quote:
Firstly, it takes the type region, instead of the type rect, which seems to be used much more often, why is this?

A region is a group of rects.

To create a region :

Collapse JASS:
function what takes rect r, trigger t returns nothing
     local region MyRegion = CreateRegion()
     call RegionAddRect(MyRegion, r)
     call TriggerRegisterEnterRegion(t, MyRegion, null)
endfunction

You can also define that boolexpr filter (condition)
02-18-2007, 08:57 PM#3
Omnikron13
I believe I know what a region is now, and why you may want to use one, but it leaves me wondering why there is no native for unit entering rect events...

Also, what exactly is a boolexpr, then?
02-19-2007, 12:59 AM#4
Pyrogasm
It's a filter that's used mainly for units. Example:
Collapse JASS:
function Boolexpr_Demo takes nothing returns boolean
    return GetWidgetLife(GetFilterUnit()) > 350.0
endfunction

function Some_Function takes nothing returns nothing
    local boolexpr B = Condition( function Boolexpr_Demo )
    local group G = CreateGroup()
    call GroupEnumUnitsInRange(G, 195.58, 3372.25, 500.00, B)
    call DestroyGroup(G)
    call DestroyBoolExpr(B)
    set G = null
    set B = null
endfunction

//Alternatively

function Some_Other_Function takes nothing returns nothing
    local group G = CreateGroup()
    call GroupEnumUnitsInRange(G, 195.58, 3372.25, 500.00, Condition(function Boolexpr_Demo))
    call DestroyGroup(G)
    set G = null
endfunction
The above functions would set G = units within 500 of the point (195.58, 3372.25) with life greater than 350. Boolexprs are handles, and thus must be destroyed with the call DestroyBoolExpr() (Typed correctly this time :D) function.

A boolexpr can also be null. If you replaced all instances of boolexprs in the above functions with "null", it would pick every unit.
02-19-2007, 01:10 AM#5
Omnikron13
Ah, thanks. =)

And also, you've reminded me to begin on fixing the leaks in my code... =P
02-19-2007, 06:59 AM#6
Chocobo
You misstyped the function to destroy the boolexpr.

Collapse JASS:
function Boolexpr_Demo takes nothing returns boolean
    return GetWidgetLife(GetFilterUnit()) > 350.0
endfunction

function Some_Function takes nothing returns nothing
    local boolexpr B = Condition( function Boolexpr_Demo )
    local group G = CreateGroup()
    call GroupEnumUnitsInRange(G, 195.58, 3372.25, 500.00, B)
    call DestroyGroup(G)
    call DestroyBoolExpr(B)
    set G = null
    set B = null
endfunction

//Alternatively

function Some_Other_Function takes nothing returns nothing
    local group G = CreateGroup()
    call GroupEnumUnitsInRange(G, 195.58, 3372.25, 500.00, Condition(function Boolexpr_Demo))
    call DestroyGroup(G)
    set G = null
endfunction

Do you really need to check 2 times the same condition? But since it's a demo, it's ok.
02-19-2007, 07:07 AM#7
Pyrogasm
Eh? Where am I checking twice?