Trigger malfunctioning completely

Charapanga

New Member
Reaction score
46
It only spawns first wave, the dialog works but the buttons don't

JASS:
library Library initializer InitLib

globals
    integer SpawnIdEast = 'hfoo'
    integer SpawnIdWest = 'hfoo'
    timer spawntimer = CreateTimer()
    timerdialog spawntimerdialog = CreateTimerDialog(spawntimer)
    force EastTeam = CreateForce()
    force WestTeam = CreateForce()
    player EastSpawner = Player(10)
    player WestSpawner = Player(11)
    player EastLeader = Player(0)
    player WestLeader = Player(1)
    dialog array SpawnDialog
    button array SpawnDialogButtons
endglobals

private function Init takes nothing returns nothing
    call ForceEnumAllies(EastTeam, EastSpawner, null)
    call ForceEnumAllies(WestTeam, WestSpawner, null)
    call DisplayTextToForce(bj_FORCE_ALL_PLAYERS, "|cff00ff00Welcome to Team Line Tower Defense!|r\n|cff0000ffPlayers Red and Blue are team leaders, they can chose what creeps by typing in|r -spawns !\n|cffff0000Good luck and have fun!|r")
    call StartTimerBJ(spawntimer, true, 5)
    call TimerDialogSetTitle(spawntimerdialog, "Spawns in: ")
    call TimerDialogDisplay(spawntimerdialog, true)
    set SpawnDialog[1] = DialogCreate()
    set SpawnDialog[2] = DialogCreate()
    set SpawnDialogButtons[1] = DialogAddButton(SpawnDialog[1], "F|cffff0000ootman|r", 'F')
    set SpawnDialogButtons[2] = DialogAddButton(SpawnDialog[1], "K|cffff0000night|r", 'K')
    set SpawnDialogButtons[11] = DialogAddButton(SpawnDialog[2], "F|cffff0000ootman|r", 'F')
    set SpawnDialogButtons[12] = DialogAddButton(SpawnDialog[2], "K|cffff0000night|r", 'K')
endfunction

private function InitLib takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterTimerEvent(t, 0.01, false)
    call TriggerAddAction(t, function Init)
endfunction
    
endlibrary

scope Spawns initializer Init

private function IsEastSpawn takes nothing returns boolean
    return GetUnitTypeId(GetFilterUnit()) == SpawnIdEast and GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) >= 0.5
endfunction

private function IsWestSpawn takes nothing returns boolean
    return GetUnitTypeId(GetFilterUnit()) == SpawnIdWest and GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) >= 0.5
endfunction

private function AllUnitsAreDead takes nothing returns boolean
    local group g = CreateGroup()
    local group g1 = CreateGroup()
    call GroupEnumUnitsInRect(g, gg_rct_AreaEast, Condition(function IsEastSpawn))
    call GroupEnumUnitsInRect(g, gg_rct_AreaWest, Condition(function IsWestSpawn))
    if CountUnitsInGroup(g) + CountUnitsInGroup(g1) == 0 then 
        call DestroyGroup(g)
        call DestroyGroup(g1)
        set g = null
        set g1 = null
        return true
    endif
    call DestroyGroup(g)
    call DestroyGroup(g1)
    set g = null
    set g1 = null
    return false
endfunction

private function Actions takes nothing returns nothing
    local integer i = 0
    local unit dummy
    loop
        exitwhen i == 15
        set dummy = CreateUnit(EastSpawner, SpawnIdEast, GetRectCenterX(gg_rct_StartEast), GetRectCenterY(gg_rct_StartEast), 0)
        call IssuePointOrder(dummy, "move", GetRectCenterX(gg_rct_EndEast), GetRectCenterY(gg_rct_EndEast))
        set dummy = null
        set dummy = CreateUnit(WestSpawner, SpawnIdWest, GetRectCenterX(gg_rct_StartWest), GetRectCenterY(gg_rct_StartWest), 0)
        call IssuePointOrder(dummy, "move", GetRectCenterX(gg_rct_EndWest), GetRectCenterY(gg_rct_EndWest))
        set dummy = null
        set i = i + 1
    endloop
    call TimerDialogDisplay(spawntimerdialog, false)
    call DestroyTimerDialog(spawntimerdialog)
    call DestroyTimer(spawntimer)
    loop
        exitwhen AllUnitsAreDead()
        call TriggerSleepAction(1)
    endloop
    set spawntimer = CreateTimer()
    call StartTimerBJ(spawntimer, false, 5)
    set spawntimerdialog = CreateTimerDialog(spawntimer)
    call TimerDialogSetTitle(spawntimerdialog, "Spawns in:")
    call TimerDialogDisplay(spawntimerdialog, true)
    call TriggerRegisterTimerExpireEvent(GetTriggeringTrigger(), spawntimer)
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger t  = CreateTrigger(  )
    call TriggerRegisterTimerExpireEvent(t, spawntimer)
    call TriggerAddAction( t, function Actions )
endfunction

endscope

scope SpawnDialog initializer Init

private function Actions takes nothing returns nothing
    local player p = GetTriggerPlayer()
    local integer pn = GetPlayerId(p) + 1
    call DialogDisplayBJ(true, SpawnDialog[pn], p)
    if pn == 2 then
    call DisplayTextToForce(WestTeam, "|cff00ff00Player|r |cff0000ffBlue|r |cff00ff00will now choose the spawns!|r")
    elseif pn == 1 then
    call DisplayTextToForce(EastTeam, "|cff00ff00Player|r |cffff0000Red|r |cff00ff00will now choose the spawns!|r")
    endif
endfunction

private function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterPlayerChatEvent(t, EastLeader, "-spawns", true)
    call TriggerRegisterPlayerChatEvent(t, WestLeader, "-spawns", true)
    call TriggerAddAction(t, function Actions)
    set t = null
endfunction

endscope

scope SpawnPick initializer init

private function Actions takes nothing returns nothing
    local button b = GetClickedButton()
    if b == SpawnDialogButtons[1] then
        set SpawnIdWest = 'hfoo'
        call DisplayTextToForce(bj_FORCE_ALL_PLAYERS, "Footmen will now spawn for the West Team!")
    elseif b == SpawnDialogButtons[2] then
        set SpawnIdWest = 'hkni'
        call DisplayTextToForce(bj_FORCE_ALL_PLAYERS, "Knights will now spawn for the West Team!")
    elseif b == SpawnDialogButtons[11] then
        set SpawnIdEast = 'hfoo'
        call DisplayTextToForce(bj_FORCE_ALL_PLAYERS, "Footmen will now spawn for the East Team!")
    elseif b == SpawnDialogButtons[12] then
        set SpawnIdEast = 'hkni'
        call DisplayTextToForce(bj_FORCE_ALL_PLAYERS, "Knights will now spawn for the East Team!")
    endif
endfunction

private function init takes nothing returns nothing
    local trigger t = CreateTrigger()
    local integer i = 0
    loop
        set i = i + 1
        call TriggerRegisterDialogEvent(t, SpawnDialog<i>)
        exitwhen i == 2
    endloop
    call TriggerAddAction(t, function Actions)
endfunction

endscope</i>


its 4 triggers in one so...and the library is going to be for later usage too
 

Azlier

Old World Ghost
Reaction score
461
I can't spot the problem, but I do have some code shortening tips:

You could use less triggers if you didn't use the StartTimerBJ. The TimerStart native lets you set a function to run when it expires. Also, you don't need TriggerRegisterDialogButtonEvent. TriggerRegisterDialogEvent* works just fine, if not better. DisplayTextToPlayer(GetLocalPlayer(),...) is better than DisplayTextToForce(bj_FORCE_ALL_PLAYERS,...)


*Unsure of the actual function name.
 

Azlier

Old World Ghost
Reaction score
461
Of course, as long as you don't destroy and/or null it. I think.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
Give the same hotkey for buttons in a same dialog is not a great idea, that's maybe why it doesn't work as intended.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
You don't? I've always thought that you need to so it doesn't call both functions or do other wierd stuff :p
No you don't.
The only needed to pause a timer is when you want to ... pause it :p
Or if you want to destroy it, pause it before, because it can still run.
But you shouldn't destroy a timer anyway, use TimerUtils instead.

Oh and pause/unpause a timer remove the periodic parameter of a timer

I mean if you start a timer with 5 s periodic, and you pause it after 1 s, if you unpause it it will end 4 s later and that's all.
 

Charapanga

New Member
Reaction score
46
so if i pause a periodic trigger, it will become one-shot ?
and the problem is when i click the dialog button footman or knight nothing happens
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
so if i pause a periodic trigger, it will become one-shot ?
and the problem is when i click the dialog button footman or knight nothing happens
yes you must restart it for keeping periodic after a pause.

Had you seen that you use 2 times the same hotkey for 2 buttons ?
 

Charapanga

New Member
Reaction score
46
Its not the same SpawnDialog, its an array, check again..

EDIT: Spawns fixed, dialog still not working..
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
Yes i were wrong.
Attach a test map, because of the globals rects.

Also you leak groups in the function AllUnitsAreDead, and using two time the function CountUnitsInGroup is so crap.
At least use it one time and set an integer variable.
 

Charapanga

New Member
Reaction score
46
Yes i were wrong.
Attach a test map, because of the globals rects.

Also you leak groups in the function AllUnitsAreDead, and using two time the function CountUnitsInGroup is so crap.
At least use it one time and set an integer variable.

Destroying groups and nulling them isn't enough?
And why can't i use CountUnitsInGroup?
I want it to check every 1 second so setting them into a variable isn't gonna do much
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
you have to clear the group before destroy it.
And you should use 2 globals groups instead and never destroy them, just clear.

Also for the function CountUnitsInGroup, yes it's not like you call it every 0.01 s, but it isn't a native function.

JASS:
function CountUnitsInGroup takes group g returns integer
    // If the user wants the group destroyed, remember that fact and clear
    // the flag, in case it is used again in the callback.
    local boolean wantDestroy = bj_wantDestroyGroup
    set bj_wantDestroyGroup = false

    set bj_groupCountUnits = 0
    call ForGroup(g, function CountUnitsInGroupEnum)

    // If the user wants the group destroyed, do so now.
    if (wantDestroy) then
        call DestroyGroup(g)
    endif
    return bj_groupCountUnits
endfunction
 

emjlr3

Change can be a good thing
Reaction score
395
removes the creation and null leaks of two more groups, and reduces overhead
 

phyrex1an

Staff Member and irregular helper
Reaction score
446
JASS:
 if CountUnitsInGroup(g) + CountUnitsInGroup(g1) == 0 then


just a suggestion:
JASS:
if FirstOfGroup(g)==null and FirstOfGroup(g1)==null then
If you want to be a real performance freak then try this:
JASS:

globals
     private boolean eastDead = false
     private boolean westDead = false
     private group dummyGroup = CreateGroup()
endglobals

private function EastSpawnCheck takes nothing returns boolean
    if GetUnitTypeId(GetFilterUnit()) == SpawnIdEast then
       set eastDead = eastDead and GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) &lt;= 0.5
    endif
    return false
endfunction

private function WestSpawnCheck takes nothing returns boolean
    if GetUnitTypeId(GetFilterUnit()) == SpawnIdWest then
        set westDead = westDead and GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) &lt;= 0.5
    endif
    return false
endfunction

private function AllUnitsAreDead takes nothing returns boolean
    set westDead = true
    set eastDead = true
    call GroupEnumUnitsInRect(dummyGroup, gg_rct_AreaEast, Condition(function EastSpawnCheck))
    call GroupEnumUnitsInRect(dummyGroup, gg_rct_AreaWest, Condition(function WestSpawnCheck))
    return wastDead and eastDead
endfunction

Can ofc be further "optimized" by merging eastDead and westDead to one variable :p

As for your dialog problem it seems as this line:
JASS:
call TriggerRegisterDialogEvent(t, SpawnDialog<i>)</i>

is ran before you create the dialogs, hence SpawnDialog is null for all i.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top