Efficiancy/Leak Check

theXact

New Member
Reaction score
0
hey so I'm new to JASS and this is my first spell. It works perfectly just wanted to check if there was a more efficient way or if there are any leaks in it.

EDIT: by more efficient im refering to the loop and the fact that it cycles through it every .01 seconds until the condition is met

What is happening is a projectile is shot, and the target is put to sleep when hit!

JASS:
function HauntJASS_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A01G'
endfunction

function Trig_HauntJASS_Actions takes nothing returns nothing
    local unit Caster = GetTriggerUnit()
    local unit Target = GetSpellTargetUnit()
    local integer AL = GetUnitAbilityLevel(Caster, 'A01G')
    local unit DCS
    loop
        if(GetUnitAbilityLevel(Target, 'B00J') > 0) then
            set DCS = CreateUnit(GetOwningPlayer(Caster),'e001',GetUnitX(Caster),GetUnitY(Caster),270)
            call UnitApplyTimedLife(DCS,'BTLF',0.25)
            call UnitAddAbility(DCS,'A01H')
            call SetUnitAbilityLevel(DCS,'A04Y',AL)
            call IssueTargetOrderById(DCS,OrderId("sleep"),Target)
            call SetUnitPathing(DCS,false)
            call SetUnitInvulnerable(DCS,true)
            return
        endif
        call TriggerSleepAction( 0.01 )
    endloop
endfunction

//===========================================================================
function InitTrig_HauntJASS takes nothing returns nothing
    local trigger gg_trg_HauntJASS = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_HauntJASS, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition ( gg_trg_HauntJASS, Condition (function HauntJASS_Conditions) )
    call TriggerAddAction( gg_trg_HauntJASS, function Trig_HauntJASS_Actions )
endfunction
 

Azlier

Old World Ghost
Reaction score
461
Here are some leaks:
JASS:
local unit Caster = GetTriggerUnit()
local unit Target = GetSpellTargetUnit()

Most handles (units, items, destructables...) need to be nulled before a function ends.

Since you use return, you must null them right before you return.

JASS:
set Caster = null
set Target = null
set DCS = null
return


You should learn about vJass. It can make your life a whole lot easier.
 

theXact

New Member
Reaction score
0
Thanks ill make those chages.

Also I thought I was using vJASS, i have newgen set to compile it in vJASS...? To be fair though I dont know the difference between JASS and vJASS very well, if at all... :p

EDIT: I didn't mean to use return, changed that to an exitwhen with the condition in the if statement, null statements were added at the end of the trigger
 

Exide

I am amazingly focused right now!
Reaction score
448
Thanks ill make those chages.

Also I thought I was using vJASS, i have newgen set to compile it in vJASS...? To be fair though I dont know the difference between JASS and vJASS very well, if at all... :p

You should post the edited version of your trigger, so we can check if it still got leaks.

You can still optimize your events.
TriggerRegisterAnyUnitEventBJ is a BJ.
I suggest you loop through player specific unit events, using only the players that are in the game.

vJASS is the same thing, but with more features.
Here's an introduction to JASS and vJASS:
http://www.thehelper.net/forums/showthread.php?t=125565
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top