• 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.
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!
  • ✅ The POLL for Hive's Texturing Contest #34 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!
  • ✅ The POLL for Hive's Techtree Contest #20 is OPEN! Vote for the TOP 3 FACTIONS! 🔗Click here to cast your vote!

[JASS] Very basic question regarding handles

Status
Not open for further replies.
Level 4
Joined
Jan 19, 2008
Messages
69
This is probably an incredibly stupid question.. but at what point should I null handles for max efficiency? I'd like to use my script as a reference.

It seemed natural to me that the handles should be null'ed only once they have been declared - as shown below:
JASS:
function SH_OL_conditions takes nothing returns nothing
    local trigger trig
    local unit caster
    local integer trigid
    local integer stats
    local effect sfx

    if GetSpellAbilityId() == SH_OL_spellid() then
        set caster = GetTriggerUnit()
        set stats = SH_OL_stats(SH_OL_getlevel(caster))
        set sfx = AddSpecialEffectTarget("Abilities\\Spells\\Orc\\Purge\\PurgeBuffTarget.mdl", caster, "origin")
        call SetHeroInt(caster, (GetHeroInt(caster, false)) + stats, true)
        call SetHeroAgi(caster, (GetHeroAgi(caster, false)) + stats, true)
        set trig = CreateTrigger()
        set trigid = GetHandleId (trig)
        call TriggerRegisterTimerEvent(trig, 0.2, true)
        call SaveTriggerActionHandle(udg_SH_hashtable , trigid, 0, TriggerAddAction(trig, function SH_OL_periodic))
        call SaveUnitHandle(udg_SH_hashtable, trigid, 1, caster)
        call SaveReal(udg_SH_hashtable, trigid, 2, 0.)
        call SaveReal(udg_SH_hashtable, trigid, 3, SH_OL_duration())
        call SaveInteger(udg_SH_hashtable, trigid, 4, stats)
        call SaveEffectHandle(udg_SH_hashtable, trigid, 5, sfx)
        set trig = null 
        set caster = null
        set sfx = null
    endif

endfunction

But looking at other people's code I tend to see this:
JASS:
function SH_OL_conditions takes nothing returns nothing
    local trigger trig
    local unit caster
    local integer trigid
    local integer stats
    local effect sfx

    if GetSpellAbilityId() == SH_OL_spellid() then
        set caster = GetTriggerUnit()
        set stats = SH_OL_stats(SH_OL_getlevel(caster))
        set sfx = AddSpecialEffectTarget("Abilities\\Spells\\Orc\\Purge\\PurgeBuffTarget.mdl", caster, "origin")
        call SetHeroInt(caster, (GetHeroInt(caster, false)) + stats, true)
        call SetHeroAgi(caster, (GetHeroAgi(caster, false)) + stats, true)
        set trig = CreateTrigger()
        set trigid = GetHandleId (trig)
        call TriggerRegisterTimerEvent(trig, 0.2, true)
        call SaveTriggerActionHandle(udg_SH_hashtable , trigid, 0, TriggerAddAction(trig, function SH_OL_periodic))
        call SaveUnitHandle(udg_SH_hashtable, trigid, 1, caster)
        call SaveReal(udg_SH_hashtable, trigid, 2, 0.)
        call SaveReal(udg_SH_hashtable, trigid, 3, SH_OL_duration())
        call SaveInteger(udg_SH_hashtable, trigid, 4, stats)
        call SaveEffectHandle(udg_SH_hashtable, trigid, 5, sfx)
    endif

    set trig = null 
    set caster = null
    set sfx = null

endfunction
 
Wait... the variable may be created without a value, but still created. Wouldn't they leak if the "if" conditions aren't met?

And the value these variables get inside the "if" doesn't remain on the variable outside/after the "if"? It does, it has to.

I always tough on using these variables in all the trigger (even the same for different stuff) and nullying at the end just those that aren't nulled during the trigger (like first of group unit)

Does this means that local variables are harmless until you assign them a value?
 
Handle Variables don't leak. The Handles those Variables are assigned to leak because the internal refernce counter of wc is too dumb to decrease itself when a local gets out of scope. No Handle assigned, no leak.
 
Status
Not open for further replies.
Back
Top