• 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] passing locals through a timer function

Status
Not open for further replies.
Here's what I have so far:

JASS:
function EMPPeriodic takes nothing returns nothing
    
endfunction

function Trig_crusaderEMPBall_Actions takes nothing returns nothing
    local location castOff
    local timer time
    local unit empBall
    local integer i
    local location empBallOff
    if GetSpellAbilityId()=='A041' then
        set castOff = PolarProjectionBJ(GetUnitLoc(GetSpellAbilityUnit()),150,GetUnitFacing(GetSpellAbilityUnit()))
        set empBall = CreateUnit(GetOwningPlayer(GetSpellAbilityUnit()),'h00H',GetLocationX(castOff),GetLocationY(castOff),GetUnitFacing(GetSpellAbilityUnit()))
        call UnitApplyTimedLife(empBall,'BTLF',5)
        set time = CreateTimer()
        set i = 0
        call TimerStart(time,.03,true,function EMPPeriodic)
    endif
endfunction

function InitTrig_crusaderEMPBall takes nothing returns nothing
    set gg_trg_crusaderEMPBall = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_crusaderEMPBall,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddAction(gg_trg_crusaderEMPBall,function Trig_crusaderEMPBall_Actions)
endfunction

And here's what I'd like to have inside EMPPeriodic:

JASS:
set i = i+1
if i > 200 then
call DestroyTimer(time)
endif
set empBallOff = PolarProjectionBJ(GetUnitLoc(empBall),15,GetUnitFacing(empBall))
call SetUnitX(empBall,GetLocationX(empBallOff))
call SetUnitY(empBall,GetLocationY(empBallOff))

In the past I've used triggers or globals, but I understand there's a way to use locals/timers as well. What am I doing wrong?
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
In this case, you could use vJass and do a "stack" of sorts;

JASS:
scope TheSpell
    globals
        private timer T = CreateTimer()
        private integer max = 0
        private Data array darr
    endglobals
    private struct Data
        unit dummy
        //other stuff
    endstruct
    private function Loop takes nothing returns nothing
        local integer i = 0
        local Data dat
        loop
            exitwhen i >= max
            set dat = darr[i]
            //do stuff with dat
            if <instance is finished> then
                //cleanup
                call dat.destroy()
                set max = max - 1
                set darr[i] = darr[max]
                if max == 0 then
                    call PauseTimer(T)
                endif
            else
                set i = i + 1
            endif
        endloop
    endfunction
    private function Actions takes nothing returns nothing
        local Data dat = Data.create()
        //setup
        set darr[max] = dat
        if max == 0 then
            call TimerStart(T,.03,true,function Loop)
        endif
        set max = max + 1
    endfunction
    //etc
endscope
Uncompiled, it's just a concept, but it should convey the idea.
 
Status
Not open for further replies.
Top