• 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.

Can't get TriggerExecute() to work.

Status
Not open for further replies.
Level 4
Joined
Feb 2, 2009
Messages
71
Look at the bottom of the Actions function of GameMode.
I am calling TriggerExecute(gg_trg_RoundPresets).
All the code of GameMode works fine, but gg_trg_RoundPresets is not executed.

GameMode:
JASS:
scope gameMode initializer Init

globals
    integer gameMode = 0
    constant integer GM_RANDOM_EACH_ROUND = 0
    constant integer GM_RANDOM_ONCE = 1
    constant integer GM_CHOOSE_EACH_ROUND = 2
    constant integer GM_CHOOSE_ONCE = 3

    dialog chooseGameMode = DialogCreate()
    button randomEachRound = DialogAddButton(chooseGameMode, "Random Each Round", 1)
    button randomOnce = DialogAddButton(chooseGameMode, "Random Once", 2)
    button chooseEachRound = DialogAddButton(chooseGameMode, "Choose Each Round", 3)
    button chooseOnce = DialogAddButton(chooseGameMode, "Choose Once", 4)
endglobals

private function Actions takes nothing returns nothing
    local button clickedButton = GetClickedButton()
    
    if clickedButton == randomEachRound then
        set gameMode = GM_RANDOM_EACH_ROUND
        call DisplayTextToForce(bj_FORCE_ALL_PLAYERS, "A random mode will be set each round.")
    endif
    
    if clickedButton == randomOnce then
        set gameMode = GM_RANDOM_ONCE
        call DisplayTextToForce(bj_FORCE_ALL_PLAYERS, "A random mode will be set for the rest of the game.")
    endif
    
    if clickedButton == chooseEachRound then
        set gameMode = GM_CHOOSE_EACH_ROUND
        call DisplayTextToForce(bj_FORCE_ALL_PLAYERS, GetPlayerName(Player(0)) + " will choose a mode each round.")
    endif
        
    if clickedButton == chooseOnce then
        set gameMode = GM_CHOOSE_ONCE
        call DisplayTextToForce(bj_FORCE_ALL_PLAYERS, GetPlayerName(Player(0)) + " will choose a mode for the rest of the game.")
    endif
    
    call TriggerExecute(gg_trg_RoundPresets)
    call DialogDestroy(chooseGameMode)
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger Trig = CreateTrigger()
    call TriggerRegisterDialogEvent(Trig, chooseGameMode)
    call TriggerAddAction( Trig, function Actions )
endfunction

endscope

RoundPresets:
JASS:
scope roundPresets initializer Init

private function Actions takes nothing returns nothing
    call DisplayTextToForce(bj_FORCE_ALL_PLAYERS, "gg_trg_RoundPresets")
    if gameMode == GM_RANDOM_EACH_ROUND then
        set roundMode = GetRandomInt(1, 3)
        call gameModes_DisplayRoundMode()
    endif
    
    if gameMode == GM_RANDOM_ONCE then
        set roundMode = GetRandomInt(1, 3)
        call gameModes_DisplayRoundMode()
    endif
    
    if gameMode == GM_CHOOSE_EACH_ROUND then
        call DisplayTextToForce(bj_FORCE_ALL_PLAYERS, GetPlayerName(Player(0)) + " is choosing a new Round Mode.")
        call DialogSetMessage(chooseRoundMode, "Which mode do you want to play?")
        call DialogDisplay(Player(0), chooseRoundMode, TRUE)
    endif
    
    if gameMode == GM_CHOOSE_ONCE then
        call DialogSetMessage(chooseRoundMode, "Which mode do you want to play?")
        call DialogDisplay(Player(0), chooseRoundMode, TRUE)
    endif
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger Trig = CreateTrigger()
    call TriggerRegisterPlayerChatEvent(Trig, Player(0), "-start", true)
    call TriggerAddAction(Trig, function Actions)
endfunction

endscope
 
Level 14
Joined
Nov 23, 2008
Messages
187
It happens because gg_trg_RoundPresets is equal to null. Naturally, you have used local trigger in scope. Of course, you can replace local with global like that:

JASS:
private function Init takes nothing returns nothing
    set gg_trg_RoundPresets = CreateTrigger()
    call TriggerRegisterPlayerChatEvent(gg_trg_RoundPresets, Player(0), "-start", true)
    call TriggerAddAction(gg_trg_RoundPresets, function Actions)
endfunction

but I recommend to make Actions function public, and call it:

JASS:
scope roundPresets initializer Init

// public, not private
public function Actions takes nothing returns nothing
  // . . .
endfunction

// . . .

endscope

JASS:
scope gameMode initializer Init

// . . .

private function Actions takes nothing returns nothing
  // . . .
  // instead of call TriggerExecute(gg_trg_RoundPresets) we use:
  call roundPresets_Actions()
  call DialogDestroy(chooseGameMode)
endfunction

// . . .

endscope
 
Level 4
Joined
Feb 2, 2009
Messages
71
When I call the public Actions it just says
"Undeclared function roundPresets_Actions"

I use JassHelper 0.9.E.0

JASS:
call roundPresets_Actions()

JASS:
public function Actions takes nothing returns nothing
//...
endfunction
 
Level 14
Joined
Nov 23, 2008
Messages
187
Make sure, that scope roundPresets is located above than scope gameMode. Should be like that:

JASS:
scope roundPresets initializer Init
// . . .
endscope

// . . .

scope gameMode initializer Init
// . . .
endscope

And I recommend to update JassHelper to the latest version (0.9.F.5)
 
Status
Not open for further replies.
Top