• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[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