• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Help removing memory leaks?

Status
Not open for further replies.
Level 2
Joined
May 27, 2004
Messages
4
hi i never wrote a jass script b4, so well i got this in jass(just converted it from a trigger)
(=

if there are any memory leaks tell me where or some thing!


Code:
function Trig_Test_Func001Func002C takes nothing returns boolean
    if ( not ( GetOwningPlayer(GetEnumUnit()) == Player(10) ) ) then
        return false
    endif
    if ( not ( GetUnitCurrentOrder(GetEnumUnit()) == String2OrderIdBJ("") ) ) then
        return false
    endif
    return true
endfunction

function Trig_Test_Func001Func003C takes nothing returns boolean
    if ( not ( GetOwningPlayer(GetEnumUnit()) == Player(11) ) ) then
        return false
    endif
    if ( not ( GetUnitCurrentOrder(GetEnumUnit()) == String2OrderIdBJ("") ) ) then
        return false
    endif
    return true
endfunction

function Trig_Test_Func001A takes nothing returns nothing
    call SetUnitLifePercentBJ( GetEnumUnit(), ( GetUnitLifePercent(GetEnumUnit()) - 5.00 ) )
    if ( Trig_Test_Func001Func002C() ) then
        call IssuePointOrderLocBJ( GetEnumUnit(), "attack", GetRectCenter(gg_rct_Move_to_2) )
    else
    endif
    if ( Trig_Test_Func001Func003C() ) then
        call IssuePointOrderLocBJ( GetEnumUnit(), "attack", GetRectCenter(gg_rct_Move_to_1) )
    else
    endif
endfunction

function Trig_Test_Actions takes nothing returns nothing
    call ForGroupBJ( GetUnitsInRectAll(gg_rct_Arena), function Trig_Test_Func001A )
endfunction

//===========================================================================
function InitTrig_Test takes nothing returns nothing
    set gg_trg_Test = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Test, 5.00 )
    call TriggerAddAction( gg_trg_Test, function Trig_Test_Actions )
endfunction

tnx alot
 
Level 5
Joined
May 22, 2006
Messages
150
As he said, he has no idea about JASS, so this is a pretty useless comment. ~~

I will see, what can be done in a minute or two:
JASS:
function Trig_Test_Func001A takes nothing returns nothing
  local unit tempUnit
  local location tempLocation
  set tempUnit = GetEnumUnit()
  call SetUnitState(tempUnit,UNIT_STATE_LIFE,GetUnitState(tempUnit,UNIT_STATE_MAX_LIFE) * RMaxBJ(0,GetUnitLifePercent(tempUnit) - 5.00) * 0.01)
  if GetOwningPlayer(tempUnit) == Player(10) and GetUnitCurrentOrder(tempUnit) == OrderId("") then
    set tempLocation = Location(GetRectCenterX(gg_rct_Move_to_2),GetRectCenterY(gg_rct_Move_to_2))
    call IssuePointOrderLoc(tempUnit,"attack",tempLocation)
    call RemoveLocation(tempLocation)
  endif
  if GetOwningPlayer(tempUnit) == Player(11) and GetUnitCurrentOrder(tempUnit) == OrderId("") then
    set tempLocation = Location(GetRectCenterX(gg_rct_Move_to_1),GetRectCenterY(gg_rct_Move_to_1))
    call IssuePointOrderLoc(tempUnit,"attack",tempLocation)
    call RemoveLocation(tempLocation)
  endif
  set tempUnit = null
  set tempLocation = null
endfunction

function Trig_Test_Actions takes nothing returns nothing
    local group tempGroup = GetUnitsInRectMatching(gg_rct_Arena,null)
    call ForGroup(tempGroup,function Trig_Test_Func001A)
    call DestroyGroup(tempGroup)
    set tempGroup = null
endfunction

function InitTrig_Test takes nothing returns nothing
  set gg_trg_Test = CreateTrigger()
  call TriggerRegisterTimerEvent(gg_trg_Test,5.00,true)
  call TriggerAddAction(gg_trg_Test,function Trig_Test_Actions)
endfunction
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
(a few changes)

JASS:
function Trig_Test_Actions takes nothing returns nothing
    local group g = CreateGroup()
    local unit u
    local location tempLocation
    call GroupEnumUnitsInRect(g, gg_rct_Arena, null)
    loop
        set u = FristOfGroup( g )
        exitwhen u == null
        call SetUnitState(u,UNIT_STATE_LIFE,GetUnitState(u,UNIT_STATE_MAX_LIFE) * RMaxBJ(0,GetUnitLifePercent(u) - 5.00) * 0.01)
        if GetOwningPlayer(u) == Player(10) and GetUnitCurrentOrder(u) == 0 then
            set tempLocation = Location(GetRectCenterX(gg_rct_Move_to_2),GetRectCenterY(gg_rct_Move_to_2))
            call IssuePointOrderLoc(u,"attack",tempLocation)
            call RemoveLocation(tempLocation)
        endif
        if GetOwningPlayer(u) == Player(11) and GetUnitCurrentOrder(u) == OrderId("") then
            set tempLocation = Location(GetRectCenterX(gg_rct_Move_to_1),GetRectCenterY(gg_rct_Move_to_1))
            call IssuePointOrderLoc(u,"attack",tempLocation)
            call RemoveLocation(tempLocation)
        endif
        call GroupRemoveUnit( g, u )
    endloop
    call DestroyGroup(g)
    set g = null
    set tempLocation = null
endfunction
 
function InitTrig_Test takes nothing returns nothing
    set gg_trg_Test = CreateTrigger()
    call TriggerRegisterTimerEvent(gg_trg_Test,5.00,true)
    call TriggerAddAction(gg_trg_Test,function Trig_Test_Actions)
endfunction
 
Status
Not open for further replies.
Top