• 🏆 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 Triggers

Status
Not open for further replies.
Level 4
Joined
Feb 2, 2009
Messages
71
vJass Triggers

I thought I knew what I was doing when writing this, but obviously I didn't.
I chose to do like this because I wanted more structure in my game mechanics.

1. The first trigger is a library containing globals and functions.

2. The second trigger is in which the "triggers" are created, adding events and actions.
The actions that are called is functions from the first trigger's library.

Do not analyze the content of the functions.
My question is why only the first trigger (startOfGame) is working.

Nothing happens when I press the Buttons of the Dialog.

1.
JASS:
//-----------------------
//  Game Globals
//-----------------------
globals
    dialog Dialog           = DialogCreate()
    timer Tim               = CreateTimer()
    timerdialog TimDialog   = CreateTimerDialog(Tim)
    
    constant integer NrOfModes      = 3
    boolean array Mode [NrOfModes]
    constant integer MODE_RANDOM    = 0
    constant integer MODE_SIDES     = 1
    constant integer MODE_FORTRESS  = 2
    constant integer MODE_GUERILLA  = 3
    
    boolean MatchOn = false
    boolean SandboxOn = false
    boolean Pause = false
    
    button Btn_Random
    button Btn_Sides
    button Btn_Fortress
    button Btn_Guerilla
endglobals




//-----------------------
//  Game Structure
//-----------------------

library dialogs
    public function Mode takes nothing returns nothing
        call DialogSetMessage(Dialog, "Choose Mode!")
        set Btn_Random = DialogAddButton(Dialog, "Random", 0)
        set Btn_Sides = DialogAddButton(Dialog, "Sides", 1)
        set Btn_Fortress = DialogAddButton(Dialog, "Fortress", 2)
        set Btn_Guerilla = DialogAddButton(Dialog, "Guerilla", 3)
        call DialogDisplay(Player(0), Dialog, true)
        call TimerStart(Tim, 10.0, false, null)
        call TimerDialogSetTitle(TimDialog, "Round Starts In")
        call TimerDialogDisplay(TimDialog, true)
    endfunction
endlibrary

library terrain
    public function PrepareTerrain takes nothing returns nothing
        call DisplayTextToForce(bj_FORCE_ALL_PLAYERS, "Preparing terrain")
    endfunction
endlibrary

library mode requires phase
    public function Sides takes nothing returns nothing
        call DisplayTextToForce(bj_FORCE_ALL_PLAYERS, "Mode: Sides")
        call PauseTimer(Tim)
        call TimerDialogDisplay(TimDialog, false)
        set Mode[MODE_SIDES] = true
        call phase_sandbox_Start()
    endfunction
    
    public function Fortress takes nothing returns nothing
        call DisplayTextToForce(bj_FORCE_ALL_PLAYERS, "Mode: Fortress")
        set Mode[MODE_FORTRESS] = true
        call phase_sandbox_Start()
    endfunction
    
    public function Guerilla takes nothing returns nothing
        call DisplayTextToForce(bj_FORCE_ALL_PLAYERS, "Mode: Guerilla")
        set Mode[MODE_GUERILLA] = true
        call phase_sandbox_Start()
    endfunction
    
    public function Random takes nothing returns nothing
        local integer i = GetRandomInt(1, NrOfModes)
        call DisplayTextToForce(bj_FORCE_ALL_PLAYERS, "Setting random Mode")
        if i == MODE_SIDES then
            call Sides()
        elseif i == MODE_FORTRESS then
            call Fortress()
        elseif i == MODE_GUERILLA then
            call Guerilla()
        endif
    endfunction
endlibrary

library phase
    scope match
        private function End takes nothing returns nothing
            set MatchOn = false
        endfunction
        
        public function Start takes nothing returns nothing
            set MatchOn = true
        endfunction
    endscope
    
    scope sandbox
        private function End takes nothing returns nothing
            set SandboxOn = false
        endfunction
        
        public function Start takes nothing returns nothing
            set SandboxOn = true
        endfunction
    endscope
    
    scope init
        public function Preparations takes nothing returns nothing
            call dialogs_Mode()
        endfunction
    endscope
endlibrary

2.
JASS:
scope startOfGame initializer Init
    public function Init takes nothing returns nothing
        local trigger Trig = CreateTrigger()
        call TriggerRegisterTimerEvent(Trig, 0.01, false)
        call TriggerAddAction(Trig, function phase_init_Preparations)
    endfunction
endscope

scope modeSidesClicked initializer Init
    public function Init takes nothing returns nothing
        local trigger Trig = CreateTrigger()
        call TriggerRegisterDialogButtonEvent(Trig, Btn_Sides)
        call TriggerAddAction(Trig, function mode_Sides)
    endfunction
endscope

scope modeFortressClicked initializer Init
    public function Init takes nothing returns nothing
        local trigger Trig = CreateTrigger()
        call TriggerRegisterDialogButtonEvent(Trig, Btn_Fortress)
        call TriggerAddAction(Trig, function mode_Fortress)
    endfunction
endscope

scope modeGuerillaClicked initializer Init
    public function Init takes nothing returns nothing
        local trigger Trig = CreateTrigger()
        call TriggerRegisterDialogButtonEvent(Trig, Btn_Guerilla)
        call TriggerAddAction(Trig, function mode_Guerilla)
    endfunction
endscope

scope modeRandomClicked initializer Init
    public function Init takes nothing returns nothing
        local trigger Trig = CreateTrigger()
        call TriggerRegisterDialogButtonEvent(Trig, Btn_Random)
        call TriggerAddAction(Trig, function mode_Random)
    endfunction
endscope

Can anyone explain this to me? Any info on how triggers are created and works is much appreciated.

If there are any good tutorials dealing with vJass triggers please link.
 

peq

peq

Level 6
Joined
May 13, 2007
Messages
171
Maybe you call
JASS:
call TriggerRegisterDialogButtonEvent(Trig, Btn_Sides)
before Btn_Sides is created which would probably also crash the thread.
If this is the problem you could solve it by using the generic event which also is used in GUI or add the event to that trigger after the button is created.
 
Level 4
Joined
Feb 2, 2009
Messages
71
You are absolutely right peq.
I solved it by using the TriggerRegisterDialogEvent
instead of TriggerRegisterDialogButtonEvent
and instead adding a Condition, which is only run once the trigger is triggered, and not during map-loading.

Thank you!

JASS:
scope modeRandomClicked initializer Init
    private function Conditions takes nothing returns boolean
        return (GetClickedButton() == Btn_Random)
    endfunction
    
    public function Init takes nothing returns nothing
        local trigger Trig = CreateTrigger()
        call TriggerRegisterDialogEvent(Trig, Dialog)
        call TriggerAddCondition(Trig, Condition(function Conditions))
        call TriggerAddAction(Trig, function mode_Random)
    endfunction
endscope
 
Status
Not open for further replies.
Top