• 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] ForGroup / EnableTrigger not working properly together..?

Status
Not open for further replies.
Level 15
Joined
Nov 30, 2007
Messages
1,202
Trigger A has a section which adds a unit to a unit group and then starts trigger B if it's already not running:

JASS:
        ...
        call GroupAddUnit(udg_FS_flames, flame)
        if (IsTriggerEnabled(gg_trg_UpdateFlames) == false) then
            call EnableTrigger(gg_trg_UpdateFlames)
        endif

Trigger B periodiacally does some work and then disables itself once the unit group is empty:
JASS:
function FlamesIterator takes nothing returns nothing
    call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 10., "working...")
endfunction

function Trig_UpdateFlames_Actions takes nothing returns nothing
    local unit u = FirstOfGroup(udg_FS_flames)
    if (FirstOfGroup(udg_FS_flames) == null) then
        call DisableTrigger(gg_trg_UpdateFlames)
        call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 10., "DISABLED")
    else
        call ForGroup(udg_FS_flames, function FlamesIterator)
    endif
endfunction

//===========================================================================
function InitTrig_UpdateFlames takes nothing returns nothing
    set gg_trg_UpdateFlames = CreateTrigger()
    call TriggerRegisterTimerEvent(gg_trg_UpdateFlames, 0.5, true)
    call TriggerAddAction(gg_trg_UpdateFlames, function Trig_UpdateFlames_Actions)
    call DisableTrigger(gg_trg_UpdateFlames)
endfunction

It works fine the first time around, however after trigger B is done and disables properly, and then trigger A adds a new unit to the unit group and enables the trigger it disables instantly rather than doing work like the previous run.

Any ideas?

A session looks like this:

STARTED
working...
working...
working...
DISABLED
STARTED
DISABLED

As illustrated the second time it just disables instantly.
 
Last edited:
Level 15
Joined
Nov 30, 2007
Messages
1,202
  • Is it ensured the unit that's added doesn't equal "null"?
  • Is it ensured the unit being the first unit inside the group is not being removed during the game? (removed units stay as "null" inside a unit group)
If it's not helping please post a demo.

The unit dies, and I suppose that could make it null? Unit added are never null. I can post the map if you want.
 
Level 15
Joined
Nov 30, 2007
Messages
1,202
A dead unit alone won't be null, but if the unit decayed, then it will be removed from game and equal null.

Thanks. My implementation of IsUnitGroupEmpty was wrong, changed it to this which fixed the issue. I blame me remebering something about people prefering ForLoop with exitwhen u == null, oh well.

JASS:
function FlamesIterator takes nothing returns nothing 
    local unit u = GetEnumUnit()
    local real r = GetUnitState(u, UNIT_STATE_LIFE)/GetUnitState(u, UNIT_STATE_MAX_LIFE)
    call SetUnitScale(u, r, r, r)
    call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 10., "working...")
    set bj_isUnitGroupEmptyResult = false
endfunction 

function Trig_UpdateFlames_Actions takes nothing returns nothing
    set bj_isUnitGroupEmptyResult = true
    call ForGroup(udg_FS_flames, function FlamesIterator)
    if (bj_isUnitGroupEmptyResult == true) then
        call DisableTrigger(gg_trg_UpdateFlames)
        call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 10., "DISABLED")
    endif
endfunction
 
Status
Not open for further replies.
Top