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
447
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.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top