[Solved] Help with dummy not beeing removed

Status
Not open for further replies.
Level 3
Joined
Nov 18, 2013
Messages
21
can someone explain me why is the dummy not beeing removed?

JASS:
function Turmoil_Condition takes nothing returns boolean
return GetSpellAbilityId() == 'A003'
endfunction

function Timer takes nothing returns nothing
local timer t = GetExpiredTimer()
call DestroyTimer(t)
set t = null
endfunction

function Turmoil_Actions takes nothing returns nothing
local unit caster = GetTriggerUnit()
local location p = GetSpellTargetLoc()
local group target = CreateGroup()
local unit temp = null
local real dmg = 20 + 35*GetUnitAbilityLevel(caster, 'A003')
local effect sfx = AddSpecialEffectLoc("war3mapImported\\Swashbuckler_Turmoil_Effect.MDX", p)
local timer t = CreateTimer()
local real r
local unit dummy = null
call TimerStart(t, 2., false, function Timer)
call CreateUnitAtLoc(GetOwningPlayer(caster), 'h004', p, 0.)
set dummy = bj_lastCreatedUnit
call UnitApplyTimedLife(dummy, 'BTFL', 2.)
call ShowUnit(caster, false)
    loop
        call GroupEnumUnitsInRangeOfLoc(target, p, 500, null)
        set temp = GroupPickRandomUnit(target)
        set r = TimerGetRemaining(t)
        exitwhen r == 0
        if (IsUnitEnemy(temp, GetOwningPlayer(caster))) and (IsUnitAliveBJ(temp)) and (not IsUnitType(temp, UNIT_TYPE_STRUCTURE)) then
        call UnitDamageTarget(caster, temp, dmg, true, false, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_NORMAL, null)
        call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Orc\\Devour\\DevourEffectArt.mdl", temp, "chest"))
        call PolledWait(0.2)
        else
        call GroupRemoveUnit(target, temp)
        endif
    endloop
loop
    set temp = FirstOfGroup(target)
    exitwhen temp == null
    call GroupRemoveUnit(target, temp)
endloop
call ShowUnit(caster, true)
call SetUnitPositionLoc(caster, p)
call SelectUnitForPlayerSingle(caster, GetOwningPlayer(caster))
call PanCameraToLocForPlayer(GetOwningPlayer(caster), GetUnitLoc(caster))
call DestroyTimer(t)
call DestroyGroup(target)
call DestroyEffect(sfx)
set t=null
set sfx = null
set target = null
set temp = null
set p = null
set caster = null
set dummy = null
endfunction

function InitTrig_Turmoil takes nothing returns nothing
set gg_trg_Turmoil = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(gg_trg_Turmoil, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(gg_trg_Turmoil, Condition(function Turmoil_Condition))
call TriggerAddAction(gg_trg_Turmoil, function Turmoil_Actions)
endfunction
 
Last edited by a moderator:
Level 42
Joined
Feb 27, 2007
Messages
5,273
CreateUnitAtLoc doesn't set bj_lastCreatedUnit, so the dummy variable is never assigned in the following lines:
JASS:
call CreateUnitAtLoc(GetOwningPlayer(caster), 'h004', p, 0.)
set dummy = bj_lastCreatedUnit
If you look at the CreateUnitAtLoc native you'll notice it returns a unit as its output so you can conveniently just do:
JASS:
native CreateUnitAtLoc takes player id, integer unitid, location loc, real face returns unit
//...
local unit dummy = CreateUnitAtLoc(...)

Protip: don't use locations. Like at all if you can avoid them. GetSpellTargetX/Y(), CreateUnit(), SetUnitX/Y(), etc. are your friends.
 
Level 3
Joined
Nov 18, 2013
Messages
21
CreateUnitAtLoc doesn't set bj_lastCreatedUnit, so the dummy variable is never assigned in the following lines:
JASS:
call CreateUnitAtLoc(GetOwningPlayer(caster), 'h004', p, 0.)
set dummy = bj_lastCreatedUnit
If you look at the CreateUnitAtLoc native you'll notice it returns a unit as its output so you can conveniently just do:
JASS:
native CreateUnitAtLoc takes player id, integer unitid, location loc, real face returns unit
//...
local unit dummy = CreateUnitAtLoc(...)

Protip: don't use locations. Like at all if you can avoid them. GetSpellTargetX/Y(), CreateUnit(), SetUnitX/Y(), etc. are your friends.

Thanks, I'm just starting on JASS, you were of great help. May I ask why not using locations?
 
Level 42
Joined
Feb 27, 2007
Messages
5,273
Locations are handle objects, which take significantly more memory to store than a floating point real number. They also require that you properly destroy/remove them when you're done. X/Y coordinates don't need to be cleaned up and you can do math on them directly to transform/move/animate.
 
Status
Not open for further replies.
Top