• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

Boolexpr question

Status
Not open for further replies.
Level 13
Joined
Jan 2, 2016
Messages
973
Okay, I'm thinking to start using a boolexpr for 1 of my systems.
However, I have a question.
After seeing this:
JASS:
function GetUnitsInRangeOfLocMatching takes real radius, location whichLocation, boolexpr filter returns group
    local group g = CreateGroup()
    call GroupEnumUnitsInRangeOfLoc(g, whichLocation, radius, filter)
    call DestroyBoolExpr(filter)
    return g
endfunction
I started wondering what happens here. More specificly with the boolexpr.

If I do something like this:
JASS:
function FilterFunc takes nothing returns boolean
    return IsUnitEnemy(GetFilterUnit(), udg_FilterPlayer)
endfunction

function test takes nothing returns nothing
    set udg_FilterPlayer = GetTriggerPlayer()
    set udg_TempGroup = GetUnitsInRangeOfLocMatching(1000.00, udg_TestPoint, Condition(function FilterFunc))
    call ForGroup(//.....

Will this be usable only once since the boolexpr is destroyed or will I be able to use it as many times as I want to? And if it's the latter - why?? Isn't the boolexpr getting destroyed? Or perhaps only a "link" to the boolexpr is getting destroyed?
 
Level 14
Joined
Jul 1, 2008
Messages
1,314
I think, each time, that function test is run, a new boolexpr is created and destroyed after the GroupEnum.
You can test this by storing the Condition(..) expression to a variable of type boolexpr and then simply ask at the end of the function test, whether this boolexpr is null or not.
 
Level 13
Joined
Jan 2, 2016
Messages
973
Okay, I tested it for a while:
JASS:
function FilterFunc takes nothing returns boolean
    return IsUnitEnemy(GetFilterUnit(), udg_FilterPlayer)
endfunction

function Text takes nothing returns nothing
    //call BJDebugMsg("true")
endfunction

function Trig_Test_Actions takes nothing returns nothing
    local boolexpr bexpr = Condition(function FilterFunc)
    call BJDebugMsg(I2S(GetHandleId(bexpr)))
    //set udg_FilterPlayer = GetTriggerPlayer()
    //set udg_TempPoint = Location(0,0)
    //set udg_TempGroup = GetUnitsInRangeOfLocMatching(10000.00, udg_TempPoint, bexpr)
    call DestroyBoolExpr(bexpr)
    call BJDebugMsg(I2S(GetHandleId(bexpr)))
    //call ForGroup(udg_TempGroup, function Text)
    //call DestroyGroup(udg_TempGroup)
    set bexpr = null
endfunction
Seems like the boolexprs are something like links to the function, but not quite.
When a boolexpr is not destroyed - it always has the same HandleId, but when it's destroyed - it gets a new handle id the next time.

So I guess it kind a works like a global variable - if there is one - it's using it.
If there isn't one - it's creating it.

Anyways... I kind a did some other tests, but I didn't get the results I wanted:
JASS:
function FilterFunc takes nothing returns boolean
    call BJDebugMsg("ran")
    return false
endfunction

function test takes nothign returns nothing
    call Condition(FilterFunc)
endfunction
But nothing happens =/

Do boolexprs run only when calling functions that actually use them?
 
Condition(function func1) == Condition(function func2) will return true. The DestroyBoolE pr thing is a relic from a time when they used to leak when you called that function.

Edit:

Do boolexprs run only when calling functions that actually use them?

You have to add a boolexpr to a trigger and call TriggerEvaluate to run it.
 
Status
Not open for further replies.
Top