• 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] Trouble with timing on this one

Status
Not open for further replies.
Level 2
Joined
Oct 26, 2014
Messages
13
JASS:
function Detonate takes nothing returns nothing
    local unit u
    local timer x
    call DisplayTextToForce(GetPlayersAll(), "Detonate")
    set u = GetEnumUnit()
    call IssueImmediateOrder(u, "thunderclap")
    call TimerStart(x,5.0,false, null)
    call RemoveUnit(u)
    call DestroyTimer(x)
    set u = null
    set x = null
endfunction

function BombsAway takes nothing returns nothing
    local group x
    call DisplayTextToForce(GetPlayersAll(), "BombsAway")
    set x = GetUnitsOfTypeIdAll('h003')
    call ForGroup(x, function Detonate)
    call DestroyGroup(x)
    set x = null
endfunction

function Propogate takes nothing returns nothing
    local unit u
    local location loc
    local real rx
    local real ry
    call DisplayTextToForce(GetPlayersAll(), "Propogate")
    set u = GetEnumUnit()
    set rx = (GetUnitX(u)+(GetRandomReal(-300,300)))
    set ry = (GetUnitY(u)+(GetRandomReal(-300,300)))
    set loc = Location(rx,ry)
    call CreateUnitAtLoc(GetOwningPlayer(GetTriggerUnit()), 'h003', loc, GetRandomReal(0,360))
    call RemoveLocation(loc)
    set u = null
    set loc = null
endfunction


function Seedling takes nothing returns nothing
    local group g
    call DisplayTextToForce(GetPlayersAll(), "Seedling1")
    set g = GetUnitsOfTypeIdAll('h003')
    call ForGroup(g, function Propogate)
    call DestroyGroup(g)
    set g = null
endfunction

function Trig_ThunderBlossom_Conditions takes nothing returns boolean
    local location loc
    local unit c
    local real rx
    local real ry
    local timer t1 = CreateTimer()
    if (GetSpellAbilityId()=='A003') then
        set c = GetTriggerUnit()
        set loc = GetSpellTargetLoc()
        call CreateUnitAtLoc( GetOwningPlayer( GetTriggerUnit() ) , 'h003', loc , GetRandomReal(0,360) )
        call RemoveLocation(loc)
        call TimerStart(t1,2.00,false,null)
        call PauseTimer(t1)
        call Seedling()
        call TimerStart(t1,2.00,false,null)
        call PauseTimer(t1)
        call Seedling()
        call TimerStart(t1,2.00,false,null)
        call PauseTimer(t1)
        call Seedling()
        call TimerStart(t1,2.00,false,null)
        call PauseTimer(t1)
        call Seedling()
        call TimerStart(t1,2.00,false,null)
        call PauseTimer(t1)
        call Seedling()
        call TimerStart(t1,2.00,false,null)
        call PauseTimer(t1)
        call Seedling()
        call TimerStart(t1,2.00,false,null)
        call PauseTimer(t1)
        call Seedling()
        call TimerStart(t1,3.00,false,null)
        call PauseTimer(t1)
        call BombsAway()
    call RemoveLocation(loc)
    call DestroyTimer(t1)
    set t1 = null
    set c = null
    set loc = null
    endif
    return true
endfunction

function InitTrig_ThunderBlossom takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( t, Condition( function Trig_ThunderBlossom_Conditions ) )
    set t = null
endfunction

So, it performs the entirety of what the functions say to do, but there's no delay in between function calls. I think I'm misunderstanding how the native TimerStart works, or not utilizing it correctly? I've been doing some reading about timer systems, but it sounds more like they're so you can continuously reuse timers across a bunch of functions. I'd just like to get a single timer to work.

The intent with this spell is that the 'h003' unit is doubled in an ever-widening area for 2^7+1 in total when they finally fire off.

What happens instead is that they all spawn, to the eye, simultaneously, attack instantaneously and as such, cause a little bit of lag. Prior tests of 2^8 and 2^9 came close to freezing the computer up.

So it appears that the problem is that the timer I'm using to delay calls of the Seedling function aren't working at all. Where am I going wrong and how do I fix it?
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
TimerStart starts the timer in the background, so you can not stop your function's execution. By your logic, technically either the whole Jass Virtual Machine, or even the whole game should lock until the timer has run out.

It works in such a way that the timer runs in background, and when the time has come for it to reach 0 seconds time left, it will try to call the callback function specified as the last argument(in your case, nothing).

I also dont understand why you call StopTimer, but eh.

You can achieve the thing you want rather easily with recursive timeback onto the same function. Something along these lines:

JASS:
function myOtherTimeout takes nothing returns nothing
    local timer t = GetExpiredTimer()

    call BombsAway()
    call DestroyTimer(t)
    call RemoveStoredInteger(someHashtable, 0, GetHandleId(t))
    //note: GetHandleId(t) could've been optimized
endfunction

function myTimeout takes nothing returns nothing //could be whatever, return type is not part of function's signature ;)
    local timer t = GetExpiredTimer()
    local integer i = LoadInteger(someHashtable, 0, GetHandleId(t))

    if (i > 7) then
        call TimerStart(t, 3.0, false, function myOtherTimeout)
    else
        call Seedling()
        call TimerStart(t, 2.0, false, function myTimeout)
        call SaveInteger(someHashtable, 0, GetHandleId(t), i + 1)
        //notice that GetHandleId(t) could've been cached
    endif
    set t = null
endfunction

function Trig_ThunderBlossom_Conditions takes nothing returns nothing
    local timer t = null
    ...
    //do checking for spell stuff
    if (isSpellSuccessful) then
        set t = CreateTimer()
        call TimerStart(t, 0., false, function myTimeout)
        call SaveInteger(someHashtable, 0, GetHandleId(t), 0)
    endif
    set t = null
endfunction

...//the init function goes here, too lazy to copy it out

Obviously the "correct" code is not in this example
 
Status
Not open for further replies.
Top