[Simple] Does this leak and can it be improved

R 3 T R O

New Member
Reaction score
12
Initialization
JASS:
function Trig_Initialization_Actions takes nothing returns nothing
    set udg_ZombiePoints[1] = GetRectCenter(gg_rct_UndeadSpawn1)
    set udg_ZombiePoints[2] = GetRectCenter(gg_rct_UndeadSpawn2)
    set udg_ZombiePoints[3] = GetRectCenter(gg_rct_UndeadSpawn3)
    set udg_ZombiePoints[4] = GetRectCenter(gg_rct_UndeadSpawn4)
    set udg_ZombiePoints[5] = GetRectCenter(gg_rct_UndeadSpawn5)
    set udg_ZombiePoints[6] = GetRectCenter(gg_rct_UndeadSpawn6)
    set udg_ZombiePoints[7] = GetRectCenter(gg_rct_UndeadSpawn7)
endfunction

//===========================================================================
function InitTrig_Initialization takes nothing returns nothing
    set gg_trg_Initialization = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Initialization, function Trig_Initialization_Actions )
endfunction


This trigger will be fired every 50 seconds.

Proximity Spawn
JASS:
function ProximitySpawn takes nothing returns nothing
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = 7
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        call CreateNUnitsAtLoc( 1, 'nzom', Player(bj_PLAYER_NEUTRAL_EXTRA), udg_ZombiePoints[GetForLoopIndexA()], bj_UNIT_FACING )
        call CreateNUnitsAtLoc( 1, 'n008', Player(bj_PLAYER_NEUTRAL_EXTRA), udg_ZombiePoints[GetForLoopIndexA()], bj_UNIT_FACING )
        call CreateNUnitsAtLoc( 1, 'ugho', Player(bj_PLAYER_NEUTRAL_VICTIM), udg_ZombiePoints[GetForLoopIndexA()], bj_UNIT_FACING )
        call CreateNUnitsAtLoc( 1, 'u000', Player(bj_PLAYER_NEUTRAL_VICTIM), udg_ZombiePoints[GetForLoopIndexA()], bj_UNIT_FACING )
        call RemoveLocation(udg_ZombiePoints[(Integer A)])
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
endfunction

//===========================================================================
function InitTrig_Proximity_Spawn takes nothing returns nothing
    set gg_trg_Proximity_Spawn = CreateTrigger(  )
    call TriggerRegisterTimerEvent(gg_trg_Proximity_Spawn,50.0,true)
    call TriggerAddAction( gg_trg_Proximity_Spawn,function ProximitySpawn )
endfunction
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
You can probably just use this:
JASS:
function ProximitySpawn takes nothing returns nothing
    local integer i = 0
    set udg_ZombiePoints[0] = Location(GetRectCenterX(gg_rct_UndeadSpawn1),GetRectCenterY(gg_rct_UndeadSpawn1))
    set udg_ZombiePoints[1] = Location(GetRectCenterX(gg_rct_UndeadSpawn2),GetRectCenterY(gg_rct_UndeadSpawn2))
    set udg_ZombiePoints[2] = Location(GetRectCenterX(gg_rct_UndeadSpawn3),GetRectCenterY(gg_rct_UndeadSpawn3))
    set udg_ZombiePoints[3] = Location(GetRectCenterX(gg_rct_UndeadSpawn4),GetRectCenterY(gg_rct_UndeadSpawn4))
    set udg_ZombiePoints[4] = Location(GetRectCenterX(gg_rct_UndeadSpawn5),GetRectCenterY(gg_rct_UndeadSpawn5))
    set udg_ZombiePoints[5] = Location(GetRectCenterX(gg_rct_UndeadSpawn6),GetRectCenterY(gg_rct_UndeadSpawn6))
    set udg_ZombiePoints[6] = Location(GetRectCenterX(gg_rct_UndeadSpawn7),GetRectCenterY(gg_rct_UndeadSpawn7))
    loop
        exitwhen i > 6
        call CreateUnitAtLoc(Player(14),&#039;nzom&#039;,udg_ZombiePoints<i>,270)
        call CreateUnitAtLoc(Player(14),&#039;n008&#039;,udg_ZombiePoints<i>,270)
        call CreateUnitAtLoc(Player(13),&#039;ugho&#039;,udg_ZombiePoints<i>,270)
        call CreateUnitAtLoc(Player(13),&#039;u000&#039;,udg_ZombiePoints<i>,270)
        call RemoveLocation(udg_ZombiePoints<i>)
        set i = i + 1
    endloop
endfunction

//===========================================================================
function InitTrig_Proximity_Spawn takes nothing returns nothing
    set gg_trg_Proximity_Spawn = CreateTrigger()
    call TriggerRegisterTimerEvent(gg_trg_Proximity_Spawn,50,true)
    call TriggerAddAction(gg_trg_Proximity_Spawn,function ProximitySpawn)
endfunction</i></i></i></i></i>


Since you remove the location every 50 times you need to redeclare it anyway, so might as well keep it all in one trigger. You could always just use coordinates, but I decided to optimize it with the variables you currently have.
 

R 3 T R O

New Member
Reaction score
12
What would be better? Coordinates? or variables.
and thanks allot! I really appreciate it! +rep
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
Coordinates are just easier, apply to many JASS natives, and don't require any leak removal:
JASS:
function ProximitySpawn takes nothing returns nothing
    local integer i = 0
    local real array x
    local real array y
    set x[0] = GetRectCenterX(gg_rct_UndeadSpawn1)
    set x[1] = GetRectCenterX(gg_rct_UndeadSpawn2)
    set x[2] = GetRectCenterX(gg_rct_UndeadSpawn3)
    set x[3] = GetRectCenterX(gg_rct_UndeadSpawn4)
    set x[4] = GetRectCenterX(gg_rct_UndeadSpawn5)
    set x[5] = GetRectCenterX(gg_rct_UndeadSpawn6)
    set x[6] = GetRectCenterX(gg_rct_UndeadSpawn7)
    set y[0] = GetRectCenterY(gg_rct_UndeadSpawn1)
    set y[1] = GetRectCenterY(gg_rct_UndeadSpawn2)
    set y[2] = GetRectCenterY(gg_rct_UndeadSpawn3)
    set y[3] = GetRectCenterY(gg_rct_UndeadSpawn4)
    set y[4] = GetRectCenterY(gg_rct_UndeadSpawn5)
    set y[5] = GetRectCenterY(gg_rct_UndeadSpawn6)
    set y[6] = GetRectCenterY(gg_rct_UndeadSpawn7)
    loop
        exitwhen i &gt; 6
        call CreateUnit(Player(14),&#039;nzom&#039;,x<i>,y<i>,270)
        call CreateUnit(Player(14),&#039;n008&#039;,x<i>,y<i>,270)
        call CreateUnit(Player(13),&#039;ugho&#039;,x<i>,y<i>,270)
        call CreateUnit(Player(13),&#039;u000&#039;,x<i>,y<i>,270)
        set i = i + 1
    endloop
endfunction

//===========================================================================
function InitTrig_Proximity_Spawn takes nothing returns nothing
    set gg_trg_Proximity_Spawn = CreateTrigger()
    call TriggerRegisterTimerEvent(gg_trg_Proximity_Spawn,50,true)
    call TriggerAddAction(gg_trg_Proximity_Spawn,function ProximitySpawn)
endfunction</i></i></i></i></i></i></i></i>


That's how it would look with coordinates. In this case, there is no noticeable difference though. Locations basically do the same as above, except they treat the coordinates as a kind of ordered pair, but they need removal. (or else it will leak)
 
Reaction score
91
Assuming his rects would be static, it is far better to move the GetRectCenterX/Y() in the Init function so you don't need to recalculate it every 50 seconds since they will return the same value. :thup: (slight performance improvement)
 
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