• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

boolean ? boolexpr ?

Status
Not open for further replies.
Level 5
Joined
Dec 20, 2008
Messages
66
Hello,
Please help me somebody...
I don't know what's wrong there, I know that my function returns boolean, but the function GetUnitsInRectMatching requie something like boolexpr code ... ???? what is boolexpr ?:eekani:
What do I have to do?
JASS:
GetUnitsInRectMatching(GetPlayableMapRect(), IsAttackable(GetFilterUnit()))
my function IsAttackable looks like that:
JASS:
    private function IsAttackable takes unit u returns boolean // HERE YOU CAN SET UP WHICH UNITS ARE AFFECTABLE BY KNOCK AND STUN EFFECTS
        if IsUnitEnemy(u, GetOwningPlayer(caster)) == FALSE or IsUnitType(u, UNIT_TYPE_STRUCTURE) or IsUnitType(u, UNIT_TYPE_MECHANICAL) or GetWidgetLife(u) <= 0.405 or UnitHasBuffBJ(u, 'B001') then
            return FALSE
        endif
        return TRUE
    endfunction
I want that to select all units around whole map which returns TRUE if I call IsAttackable with them as in ().. :smile:
Please tell me what to do :-(
Thanks for any help
 
Level 7
Joined
Dec 31, 2005
Messages
712
boolexpr is a "converted" boolean function. You can convert it using the Condition( function YourConditionFunction)) function.

Your IsAttackable function does not need any parameters as GetFilterUnit() will always exist in boolexpr functions (also, the function you use inside Condition(...) cannot take any parameters).

Remember that boolexpr leaks. You ought to make it a global boolexpr or destroy it after using it.
 
Level 9
Joined
Nov 28, 2008
Messages
704
Boolexprs does NOT leak. It only leaks when you use the And() and Or() functions on it. They are tabled like strings.

You should use Filter(function something), not Condition.

As mentioned, your filters should take nothing and return a boolean.

Remember to efficientize your function, too. As it is, it looks like converted GUI. one big long return line could do it.

Where are you getting your "caster" variable from? Is it global? If not, your filter cant use it.
 
Level 7
Joined
Dec 31, 2005
Messages
712

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,178
Boolexprs are recycled as they are hashed so the same function will boolexpr to the same boolexpr. However, you should still destroy them if the trigger they were for (or function they were used in) will never be used again just to save some memory (why waste memory?). Luckilly you can just remove them by Conditioning the function again to get the boolexpr to remove, but even if you do not this leak is so small it does not make a difference.
 
Level 12
Joined
Sep 4, 2007
Messages
407
Someone told me destroing a boolexpr is dangerous for the map. May cause a crash or something like that. Never found that out. Anyway, i always try to avoid destroying boolexpr.

and ugh... I'd try to avoid those BJ you are using over there. Try to make equivalent functions that are more efficient (although that often makes the trigger more complex). If i recall correctly, those two BJs leaks a group each. Even if you manage do destroy the groups, destroying them leaks aswell. o_O

Edit: The BJ GetPlayableMapRect don't seem to leak but the other one...

JASS:
function GetUnitsInRectMatching takes rect r, boolexpr filter returns group
    local group g = CreateGroup()
    call GroupEnumUnitsInRect(g, r, filter)
    call DestroyBoolExpr(filter)
    return g
endfunction

I THINK doing this solves it;

JASS:
    call GroupEnumUnitsInRect(GroupYouWantStore, bj_mapInitialPlayableArea, Filter(IsAttackable))

no need to destroy boolexprs =)

plz let me know if I am wrong.
 
Status
Not open for further replies.
Top