• 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.

Leaks again

Status
Not open for further replies.
Level 4
Joined
Mar 23, 2009
Messages
78
Hello everyone, this time im trying to make a system that could give a unit ability if it's close to a tree. The main part of the code is:
JASS:
function CheckNGo takes nothing returns nothing
    local integer i=0
        if GetDestructableLife(GetEnumDestructable())>0 then
                call UnitAddAbilityBJ( 'AEev', udg_T )
                call SetUnitAbilityLevel( udg_T, 'AEev', 1 )
                call DisableTrigger( gg_trg_check )
        endif
endfunction

function FilterThis takes nothing returns boolean
    local location destLoc = GetDestructableLoc(GetFilterDestructable())
    local boolean result

    set result = DistanceBetweenPoints(destLoc, bj_enumDestructableCenter) <= bj_enumDestructableRadius
    call RemoveLocation(destLoc)
    set destLoc=null
    return result
endfunction

function Trig_check_Actions takes nothing returns nothing
    local rect r
    local location q
    set q = GetUnitLoc(udg_T)
    set bj_enumDestructableCenter = q
    set bj_enumDestructableRadius = 200
    set bj_wantDestroyGroup = true
    set r = GetRectFromCircleBJ(q, 200)
    call EnumDestructablesInRect(r, filterEnumDestructablesInCircleBJ, function CheckNGo)
    //if FilterThis()==true then
        //call UnitRemoveAbility(udg_T,'AEev')
    //endif
    call RemoveRect(r)
    call RemoveLocation(q)
    set bj_enumDestructableCenter = null
    set r=null
    set q=null
endfunction

//===========================================================================
function InitTrig_check takes nothing returns nothing
    set gg_trg_check = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_check, 0.1 )
    call TriggerAddAction( gg_trg_check, function Trig_check_Actions )
endfunction
where's a mistake?
 
Last edited:
Level 26
Joined
Aug 18, 2009
Messages
4,097
Have you set filterEnumDestructablesInCircleBJ to function FilterThis? Why this bj crap? You better not set bj_wantDestroyGroup to true. This is no unit group, it does not even create an object. Your loop will continue running even when you disable the trigger, it does not halt the current call, so your actions in CheckNGo could be done multiple times.

How does your mistake express?
 
Level 4
Joined
Mar 23, 2009
Messages
78
The first problem was a leak, of course. i fixed the code and now it looks like:
JASS:
function CheckNGo takes nothing returns nothing
    local integer i=0
        if GetDestructableLife(GetFilterDestructable())>0 then
                call UnitAddAbilityBJ( 'AEev', udg_T )
                call SetUnitAbilityLevel( udg_T, 'AEev', 1 )
                call DisableTrigger( gg_trg_checkTree )
        endif
endfunction

function FilterThis takes nothing returns boolean
    local location destLoc = GetDestructableLoc(GetFilterDestructable())
    local boolean result
    
    set result = DistanceBetweenPoints(destLoc, GetUnitLoc(udg_T)) >= bj_enumDestructableRadius
    //call DisplayTextToPlayer(Player(0),0,0,R2S(Dist(destLoc, bj_enumDestructableCenter)))
    call RemoveLocation(destLoc)
    set destLoc=null
    return result
endfunction

function Trig_checkTree_Actions takes nothing returns nothing
    local rect r
    local location q
    local boolean b

    set q = GetUnitLoc(udg_T)
    set bj_enumDestructableCenter = q
    set bj_enumDestructableRadius = 200
    set r = GetRectFromCircleBJ(q, bj_enumDestructableRadius)//RectFromCenterSizeBJ(q, 300,300)//
    call EnumDestructablesInRect(r, null, function CheckNGo)
    if FilterThis()==false then
    //set p = GetDestructableLoc(GetEnumDestructable())
    //set b=RectContainsCoords(r,GetLocationX(p),GetLocationY(p))
        call UnitRemoveAbility(udg_T,'AEev')
    endif
    call RemoveRect(r)
    call RemoveLocation(q)
    set bj_enumDestructableCenter = null
    set r=null
    set q=null
endfunction

//===========================================================================
function InitTrig_checkTree takes nothing returns nothing
    set gg_trg_checkTree = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_checkTree, 0.1)
    call TriggerAddAction( gg_trg_checkTree, function Trig_checkTree_Actions )
endfunction
but now the given ability is not removed properly. Whats the way to remove it or check a rect or distance correctly?
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
JASS:
function CheckNGo takes nothing returns nothing
    set udg_i = udg_i + 1
endfunction

function FilterThis takes nothing returns boolean
    local location destLoc
    local boolean result

    if (not GetDestructableLife(GetFilterDestructable()) > 0) then
        return false
    endif

    set desLoc = GetDestructableLoc(GetFilterDestructable())

    set result = DistanceBetweenPoints(destLoc, GetUnitLoc(udg_T)) <= bj_enumDestructableRadius

    call RemoveLocation(destLoc)

    set destLoc = null

    return result
endfunction

function Trig_checkTree_Actions takes nothing returns nothing
    local rect r
    local location q
    local boolean b

    set q = GetUnitLoc(udg_T)
    set bj_enumDestructableCenter = q
    set bj_enumDestructableRadius = 200
    set r = GetRectFromCircleBJ(q, bj_enumDestructableRadius)//RectFromCenterSizeBJ(q, 300,300)//
    set udg_i = 0

    call EnumDestructablesInRect(r, filterEnumDestructablesInCircleBJ, function CheckNGo)

    if (udg_i > 0) then
        call UnitAddAbilityBJ( 'AEev', udg_T )
        call SetUnitAbilityLevel( udg_T, 'AEev', 1 )
    else
        call UnitRemoveAbility(udg_T,'AEev')
    endif

    call RemoveRect(r)
    call RemoveLocation(q)
    set bj_enumDestructableCenter = null
    set r=null
    set q=null
endfunction

//===========================================================================
function InitTrig_checkTree takes nothing returns nothing
    set gg_trg_checkTree = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_checkTree, 0.1)
    call TriggerAddAction( gg_trg_checkTree, function Trig_checkTree_Actions )
endfunction

udg_i is a global integer var. You had the distance condition now reversed btw. You want to pick nearby destructables. And make another condition if that's really a tree. You do not even need the CheckNGo function, you could also do your actions/the counting in the filter.
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
You can take a look at this native:

JASS:
native EnumDestructablesInRect takes rect r, boolexpr filter, code actionFunc returns nothing

Notice boolexpr filter?
 
Level 4
Joined
Mar 23, 2009
Messages
78
after i used null in boolexpr parameter, trigger stopped leaking.
Thanks alot, trigger now works fine.
unfortunately ive already raised your rep
 
Status
Not open for further replies.
Top