• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] does boolexpr leak ?

Status
Not open for further replies.
i use it like this it happens multiple times so not sure if it leaks also if there is a better way for conditions tht would be nice to know also lol

JASS:
scope PlusSignKill initializer Init_Plus_Sign_Random_Kill

globals
    trigger trg_Plus_Sign_Random_Killer
endglobals

private function PlusSignKillCondition takes nothing returns boolean
    if GetTriggerUnit() == Selected_Hero_Player[0] or GetTriggerUnit() == Selected_Hero_Player[1] then
        return true
    else
        return false
    endif
endfunction

private function Trig_Plus_Sign_Random_Kill_Actions takes nothing returns nothing
    call DisplayTextToForce( GetPlayersAll(), "unit in range" )
endfunction

//===========================================================================
function Init_Plus_Sign_Random_Kill takes nothing returns nothing
    set trg_Plus_Sign_Random_Killer = CreateTrigger(  )
    call TriggerRegisterUnitInRange( trg_Plus_Sign_Random_Killer, gg_unit_h05F_0036, 125, Condition( function PlusSignKillCondition ) )
    call TriggerRegisterUnitInRange( trg_Plus_Sign_Random_Killer, gg_unit_h05F_0037, 125, Condition( function PlusSignKillCondition ) )
    call TriggerRegisterUnitInRange( trg_Plus_Sign_Random_Killer, gg_unit_h05F_0038, 125, Condition( function PlusSignKillCondition ) )
    call TriggerRegisterUnitInRange( trg_Plus_Sign_Random_Killer, gg_unit_h05F_0039, 125, Condition( function PlusSignKillCondition ) )
    call TriggerRegisterUnitInRange( trg_Plus_Sign_Random_Killer, gg_unit_h05F_0040, 125, Condition( function PlusSignKillCondition ) )
    call TriggerRegisterUnitInRange( trg_Plus_Sign_Random_Killer, gg_unit_h05F_0041, 125, Condition( function PlusSignKillCondition ) )
    call TriggerRegisterUnitInRange( trg_Plus_Sign_Random_Killer, gg_unit_h05F_0043, 125, Condition( function PlusSignKillCondition ) )
    call TriggerRegisterUnitInRange( trg_Plus_Sign_Random_Killer, gg_unit_h05F_0044, 125, Condition( function PlusSignKillCondition ) )
    call TriggerAddAction( trg_Plus_Sign_Random_Killer, function Trig_Plus_Sign_Random_Kill_Actions )
endfunction

endscope
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
in this case, you should not destroy those boolexprs because they will be used in the trigger
I dont know if when you distroy the trigger it will destroy those or not(but rather yes than no) but this is not that big deal, if you made a boolexpr every 0.01 second and keep it there, that could be problem
 
Level 16
Joined
Aug 7, 2009
Messages
1,406
1), the condition function could look like this:

JASS:
private function PlusSignKillCondition takes nothing returns boolean
    return GetTriggerUnit()==Selected_Hero_Player[0] or GetTriggerUnit()==Selected_Hero_Player[1] //I don't know why the JASS tag linebreaks this line;
endfunction

2) instead of Condition(), yould use Filter(); not that big of a deal, but it's easier to type out :)

3) you don't need to register that action; you could just put the "action" function above the condition function, and make the condition look like this:

JASS:
private function PlusSignKillCondition takes nothing returns boolean
    if GetTriggerUnit()==Selected_Hero_Player[0] or GetTriggerUnit()==Selected_Hero_Player[1] then //and this one too
        call Trig_Plus_Sign_Random_Kill_Actions()
    endif
    return false //It's important
endfunction

This actually makes the whole thing faster, and also, based on the situation, you can also have an action function with parameters, which I think is quite cool.
 
Level 4
Joined
Jan 27, 2010
Messages
133
Actually, nvm. The 'leak' in the test map was due to reference counter not reseting from GetUnitsInRectMatching.

No, using
JASS:
Condition(code)
will not leak.

Attaching better test map.
 

Attachments

  • BoolExprTest.w3x
    20.2 KB · Views: 72
er..

Condition creates a boolean expression from a function and only does so for a given function once.

If you destroy the boolean expression, it deletes that 1 and only boolean expression for the function.

The boolean expressions are stored in triggers, so deleting it would invalidate the ones stored in the triggers.

You may use Condition on a given function as many times as you like and it will always return that same original boolean expression.

It only leaks if you create it and then never ever use it : P, but using it multiple times does not continue to spam boolean expressions.

Filter extends off of boolean expression, so it's advisable to just use boolean expression (Condition).
 
Status
Not open for further replies.
Top