return leak

SFilip

Gone but not forgotten
Reaction score
634
example:
Code:
function SomeFunction takes nothing returns group
    local group ug = CreateGroup ()
    call GroupAddUnit (ug, <some unit>)
    return ug
endfunction
this leaks a unit group...however i cant fix it after i return it. so is there any way to fix this leak?

also i've been reading some functions from common.j and blizzard.j and noticed that some of them return "boolexpr". what is this variable type? is it something simular to boolean or what?

thanks in advance
 

phyrex1an

Staff Member and irregular helper
Reaction score
447
If you return the group why would you want to destroy it?
The whole point of returning something is that the function you return to can use it.

A boolexpr is a pointer to a function that returns a value, often a boolean but it can be a integer, real or string and probably a handle too.
Anyway, the point of this is that other (natives) takes boolexpr as a parameter and and 'evulates' the function the boolexpr points to.
Then the native does different actions depending on if the boolexpr evaluated to true or false/0/"" or null.

A good example on this is the 'pick ever unit in group matching condition', the condition part is a boolexpr. The native takes that boolexpr and run it for each unit that may be in the group, IE every unit in range. If the boolexpr evaluated to true then the unit will be in the returned group, else it wont.

Trigger Conditions are also boolexpr, or at least something very similar to it.

If you want to skip all thing technical stuff that I probably don't understand myself then say that a boolexpr is a function that evaluates to a boolean value depending on different conditions.
Ie if the 'matching unit' is a flying unit.
 
D

Dino.pl

Guest
Hmm, but if a function takes boolexpr, you can't simply write true or false.
Code:
call TriggerAddCondition( gg_trg_Untitled_Trigger_004, Condition( function Trig_Untitled_Trigger_004_Conditions ) ) //works
call TriggerAddCondition( gg_trg_Untitled_Trigger_004, true) //parse error
So I guess that boolexpr must point to a function. However, this function may returns nothing:
Code:
function Trig_Untitled_Trigger_004_Conditions takes nothing returns nothing
    //no parse error
endfunction
 

SFilip

Gone but not forgotten
Reaction score
634
but wait...wouldn't it leak if i define a local and skip "nulling" and destroying it afterwards? or should i do that in the trigger that calls that function?
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
The reference to the group is passed to the caller.
The variable destroys itself.


Otherwise there wouldn't be a point in using a function.
 

SFilip

Gone but not forgotten
Reaction score
634
alright got it.
thank you all
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top