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

[JASS] curious about leaks

Status
Not open for further replies.
Level 3
Joined
Aug 15, 2007
Messages
37
Here is trigger that was created GUI and just converted to JASS. What all would need to be done to clean all leaks, and what functions should I avoid using entirely?

JASS:
function Trig_ChannelManaBeginCast_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A00D' ) ) then
        return false
    endif
    return true
endfunction

function Trig_ChannelManaBeginCast_Func001C takes nothing returns boolean
    if ( not ( GetPlayerState(GetOwningPlayer(GetSpellAbilityUnit()), PLAYER_STATE_RESOURCE_GOLD) > 0 ) ) then
        return false
    endif
    return true
endfunction

function Trig_ChannelManaBeginCast_Actions takes nothing returns nothing
    if ( Trig_ChannelManaBeginCast_Func001C() ) then
        call LeaderboardSetPlayerItemValueBJ( Player(11), GetLastCreatedLeaderboard(), 0 )
        call SetPlayerStateBJ( GetOwningPlayer(GetSpellAbilityUnit()), PLAYER_STATE_RESOURCE_GOLD, ( GetPlayerState(GetOwningPlayer(GetSpellAbilityUnit()), PLAYER_STATE_RESOURCE_GOLD) - 1 ) )
    else
        call IssueImmediateOrderBJ( GetSpellAbilityUnit(), "stop" )
        call LeaderboardSetPlayerItemValueBJ( Player(11), GetLastCreatedLeaderboard(), 1 )
    endif
endfunction

//===========================================================================
function InitTrig_ChannelManaBeginCast takes nothing returns nothing
    set gg_trg_ChannelManaBeginCast = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_ChannelManaBeginCast, EVENT_PLAYER_UNIT_SPELL_CHANNEL )
    call TriggerAddCondition( gg_trg_ChannelManaBeginCast, Condition( function Trig_ChannelManaBeginCast_Conditions ) )
    call TriggerAddAction( gg_trg_ChannelManaBeginCast, function Trig_ChannelManaBeginCast_Actions )
endfunction
 
Level 3
Joined
Aug 15, 2007
Messages
37
What about GetOwningPlayer() and GetSpellAbilityUnit()? They both take non-integer arguments. (player,unit). Wouldn't those need to be nulled?
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
No leaks, but the code is sorta messy (well, it's converted, I suppose)

And they only leak in the null sense if they're stored to variables.

[jass=Cleaned Code]function Trig_ChannelManaBeginCast_Conditions takes nothing returns boolean
return GetSpellAbilityId() == 'A00D'
endfunction

function Trig_ChannelManaBeginCast_Actions takes nothing returns nothing
local player p = GetOwningPlayer(GetTriggerUnit())
if GetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD) > 0 then
call LeaderboardSetItemValue(bj_lastCreatedLeaderboard,LeaderboardGetPlayerIndex(bj_lastCreatedLeaderboard,Player(11)),0)
call SetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD,GetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD)- 1)
else
call IssueImmediateOrder(GetTriggerUnit(),"stop")
call LeaderboardSetItemValue(bj_lastCreatedLeaderboard,LeaderboardGetPlayerIndex(bj_lastCreatedLeaderboard,Player(11)),1)
endif
set p = null
endfunction

function InitTrig_ChannelManaBeginCast takes nothing returns nothing
set gg_trg_ChannelManaBeginCast = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(gg_trg_ChannelManaBeginCast,EVENT_PLAYER_UNIT_SPELL_CHANNEL)
call TriggerAddCondition(gg_trg_ChannelManaBeginCast,Condition(function Trig_ChannelManaBeginCast_Conditions))
call TriggerAddAction(gg_trg_ChannelManaBeginCast,function Trig_ChannelManaBeginCast_Actions)
endfunction[/code]
 
Status
Not open for further replies.
Top