Leak Question

newtonrox

Member
Reaction score
2
JASS:
function Trig_Spawn_Basic_Func001Func001C takes nothing returns boolean
    if ( not ( GetUnitTypeId(GetEnumUnit()) == 'h001' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Spawn_Basic_Func001A takes nothing returns nothing
local location A = GetUnitLoc(GetEnumUnit())


    if ( Trig_Spawn_Basic_Func001Func001C() ) then
       if  ( ( GetPlayerState(GetOwningPlayer(GetEnumUnit()), PLAYER_STATE_RESOURCE_FOOD_USED) < 70 ) ) then       
           

call CreateNUnitsAtLocFacingLocBJ( 5, 'h00C', GetOwningPlayer(GetEnumUnit()), A, A )
       endif    
    else
    endif
call RemoveLocation (A)

endfunction

function Trig_Spawn_Basic_Actions takes nothing returns nothing
local group u = GetUnitsInRectAll(GetPlayableMapRect())    
    
    call ForGroup( u, function Trig_Spawn_Basic_Func001A )
    call DestroyGroup(u)
    set u = null
endfunction

//===========================================================================
function InitTrig_Spawn_Basic takes nothing returns nothing
    set gg_trg_Spawn_Basic = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Spawn_Basic, 2.00 )
    call TriggerAddAction( gg_trg_Spawn_Basic, function Trig_Spawn_Basic_Actions )
endfunction


will it leak?
what's the difference between nullifying and removing/destroying a variable?
does GetEnumUnit leak when i call it?
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Wow !!! That inlining really hurts my eyes !!! How can you work with that ???!!!!

Anyways, no it won't leak, though you should null locations if I'm correct...

And the whole trigger can just be like this :

JASS:
function Trig_Spawn_Basic_Func001Func001C takes nothing returns boolean
    return GetUnitTypeId(GetEnumUnit()) == 'h001' ) )
endfunction

function Trig_Spawn_Basic_Func001A takes nothing returns nothing
    local location A = GetUnitLoc(GetEnumUnit())
        if (Trig_Spawn_Basic_Func001Func001C()) and ( ( GetPlayerState(GetOwningPlayer(GetEnumUnit()), PLAYER_STATE_RESOURCE_FOOD_USED) < 70 ) ) then 
            call CreateNUnitsAtLocFacingLocBJ( 5, 'h00C', GetOwningPlayer(GetEnumUnit()), A, A ) 
        endif
    call RemoveLocation (A)
    set A = null
endfunction

function Trig_Spawn_Basic_Actions takes nothing returns nothing
    local group u = GetUnitsInRectAll(GetPlayableMapRect())    
    call ForGroup( u, function Trig_Spawn_Basic_Func001A )
    call DestroyGroup(u)
    set u = null
endfunction

//===========================================================================
function InitTrig_Spawn_Basic takes nothing returns nothing
    set gg_trg_Spawn_Basic = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Spawn_Basic, 2.00 )
    call TriggerAddAction( gg_trg_Spawn_Basic, function Trig_Spawn_Basic_Actions )
endfunction
 

newtonrox

Member
Reaction score
2
thx again man ^^
and yes, location must be set to null
cuz now my map is lagless =D
lol
after 1 hour my map was crashing just because of this variable...
and well, i'm running it for about 20 minutes and it's not laggy anymore =)
 

Exide

I am amazingly focused right now!
Reaction score
448
No need to call 'Trig_Spawn_Basic_Func001Func001C'.
'CreateNUnitsAtLocFacingLocBJ' might as well be: 'CreateNUnitsAtLoc'
 

newtonrox

Member
Reaction score
2
thx as well ^^
after killing 12k units in 55 min
there's really no lag now! XD
is it worthy to set a local unit variable to GetEnumUnit()?
 

Attachments

  • Killing_Overview.jpg
    Killing_Overview.jpg
    147.3 KB · Views: 148

Komaqtion

You can change this now in User CP.
Reaction score
469
Well, yeah since you're using it so much... But that would mean that you need to alter your entire code :(

So use this :D

JASS:
function filter takes nothing returns nothing
    local integer i = 0
    local unit u = GetEnumUnit()
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    if GetUnitTypeId(u) == 'h001' and GetPlayerState(GetOwningPlayer(u), PLAYER_STATE_RESOURCE_FOOD_USED) < 70 then
        loop
        exitwhen i >= 5
            call CreateUnit(GetOwningPlayer(u), 'h00C', x,y, bj_UNIT_FACING)
            set i = i + 1
        endloop
    endif
    set u = null
endfunction

function Actions takes nothing returns nothing
    local group g = CreateGroup()
    call GroupEnumUnitsInRect(g, bj_mapInitialPlayableArea, null)
    call ForGroup(g, function filter)
    call DestroyGroup(g)
    set g = null
endfunction

//===========================================================================

function InitTrig_Spawn_Basic takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterTimerEventPeriodic(t, 2.)
    call TriggerAddAction(t, function Actions)
endfunction
 

newtonrox

Member
Reaction score
2
nice,so that's how "create n units bj" works ^^

hmmm this "filter" function...
i see it in lots of codes here in the forum
is it a normal condition fuction? i mean, what's the idea for it? its point...
oh and don't you have to nullify the values of X and Y ( is this called offset in english? the points in the vertical and horizontal axis)?


and can i replace bj_mapInitialPlayableArea for GetPlayableMapRect()?
 

Dinowc

don't expect anything, prepare for everything
Reaction score
223
this "filter" function...
is it a normal condition fuction? i mean, what's the idea for it?

"filter" is just a name, players tend to use names that point on what are they doing

in this case, filter is not a good name, because ForGroup() function runs actions for each unit in the group and has nothing to do with "filtering"

anyway, it's always better to create just 1 global group at map init

so instead of this:

JASS:
function Actions takes nothing returns nothing
    local group g = CreateGroup()
    call GroupEnumUnitsInRect(g, bj_mapInitialPlayableArea, null)
    call ForGroup(g, function filter)
    call DestroyGroup(g)
    set g = null
endfunction


do this:

JASS:
function Actions takes nothing returns nothing
    call GroupEnumUnitsInRect(udg_g, bj_mapInitialPlayableArea, Condition(function filter))
endfunction


I don't know how you declare globals in Jass... (I know in vJass)

also change the filter function to this:

JASS:
function filter takes nothing returns boolean // notice the return
    local integer i = 0
    local unit u = GetFilterUnit() // not GetEnumUnit()
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    if GetUnitTypeId(u) == 'h001' and GetPlayerState(GetOwningPlayer(u), PLAYER_STATE_RESOURCE_FOOD_USED) < 70 then
        loop
        exitwhen i >= 5
            call CreateUnit(GetOwningPlayer(u), 'h00C', x,y, bj_UNIT_FACING)
            set i = i + 1
        endloop
    endif
    set u = null

    return false // always return false so the group will be "empty"
endfunction


in this case "filter" is a good name because we are filtering :p
this is a faster way, use it always if you gonna group units instantly

and can i replace bj_mapInitialPlayableArea for GetPlayableMapRect()?

if I'm correct, GetPlayableMapRect() is a BJ that actually returns bj_mapInitialPlayableArea so yeah, but it's pointless
 

newtonrox

Member
Reaction score
2
wait, i'm noob at jass XD
i've searched for this function "GroupEnumUnitsInRect" in NewGen fuction list and didn't find any explanation about it.
This function is the "Pick every unit and do action" from GUI right (i'm still converting GUI into jass when i begin any trigger =p)?

and when you return false to its boolexpr parameter it leaves the group as empty(nullyfied) after the loop?
sry for my noobness...
 

Dinowc

don't expect anything, prepare for everything
Reaction score
223
i'm still converting GUI into jass when i begin any trigger =p

I never learned Jass that way

it just makes junk of a code

if you're still new in Jass then start learning vJass instead (there is a nice tutorial about it)

when you return false to its boolexpr parameter it leaves the group as empty(nullyfied) after the loop?
yes
 

Viikuna

No Marlo no game.
Reaction score
265
He is right. Learning from converted GUI can be a pain in the ass, because its pretty messy and terrible and everything.

People have different way sof learning, though. I always learned by example, so I just read other peoples codes to find out how they do their stuff.

edit. Komaqtion you should know that calling GroupEnum for temporary group leaks, which is why we never use DestroyGroup, but recycle our groups instead. Dinowc´s method is the right way to do this, one global groups is everything you need for your GroupEnum needs.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top