• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] passing locals through a timer function

Status
Not open for further replies.

Cokemonkey11

Spell Reviewer
Level 29
Joined
May 9, 2006
Messages
3,534
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