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

[Solved] Dialog button clicks are not being caught for some reason

Status
Not open for further replies.
Level 3
Joined
Aug 24, 2016
Messages
27
An "Dialog - A dialog button is clicked for *dialog_name*" event is simply not working for me. Long story short, it's not my first year with the editor, and I checked all the obvious stuff.

I'm using Jass New Gen Pack 5d Exp2, is this something of a bug in this version? Or else I just don't get it.
 
Level 3
Joined
Aug 24, 2016
Messages
27
03oAFkLarZA.jpg


4JepnclEF94.jpg


I don't think it has anything to do with the triggers (I tested), but I guess people will ask me to show them anyways.
 
Level 13
Joined
Mar 24, 2013
Messages
1,105
I guess try clearing the dialog first? Also I didn't see a "Create New Dialog" option, I'm assuming its just calling a DialogCreate() but I think global dialogs get created on their own.

But my sample here worked for me.

  • Test
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • Dialog - Clear Dialog
      • Dialog - Change the title of Dialog to Title
      • Dialog - Create a dialog button for Dialog labelled Test
      • Set DialogButton = (Last created dialog Button)
      • Dialog - Show Dialog for Player 1 (Red)
  • Test2
    • Events
      • Dialog - A dialog button is clicked for Dialog
    • Conditions
      • (Clicked dialog button) Equal to DialogButton
    • Actions
      • Game - Display to (All players) the text: hello world
 
Level 3
Joined
Aug 24, 2016
Messages
27
So, it was the broken New Gen gui thing that broke everything. Setting variable to be a new dialog is what caused it to lose connection with the click events.
 
Level 13
Joined
Jan 2, 2016
Messages
978
Here is a working script, using dialog window. It's in vJASS, but maybe it will help?
JASS:
scope Mode

  globals
  dialog mode_window = DialogCreate()
  button no_meteorites
  button normal
  button hard
  button nightmare
  button hell
  button test
  private integer players = 0
  private integer players_total = 0
  private integer array votes
  private timer t = CreateTimer()
  endglobals

  function ModeMsg takes integer i returns nothing
  if i == 0 then
  call EnableTrigger( gg_trg_test_commands )
  call DisplayTextToForce( GetPlayersAll(), "Test mode enabled! You can use commands like: \"-time\"; \"-time ##\"; \"-mode #\"; \"-arena\"; \"-kill\"; \"-gtt\"; \"-rush\"; \"-itemo order (#)\"; \"-build\"; \"-upgrade all\"; \"-gold ##\"; \"-lumber ##\"" )
  loop
  exitwhen i > 11
  call SetPlayerState( Player(i), PLAYER_STATE_RESOURCE_LUMBER, 3500 )
  call SetPlayerState( Player(i), PLAYER_STATE_RESOURCE_GOLD, 5000 )
  set i = i + 1
  endloop
  return
  elseif i == 1 then
  call DisplayTextToForce( GetPlayersAll(), "TRIGSTR_463" )
  elseif i == 2 then
  call DisplayTextToForce( GetPlayersAll(), "Normal Mode - Normal amount of meteorites." )
  elseif i == 3 then
  call DisplayTextToForce( GetPlayersAll(), "TRIGSTR_464" )
  elseif i == 4 then
  call DisplayTextToForce( GetPlayersAll(), "TRIGSTR_465" )
  elseif i == 5 then
  call DisplayTextToForce( GetPlayersAll(), "TRIGSTR_466" )
  endif
  call SetConcLvl()
  endfunction

  private function ShowMsg takes nothing returns nothing
  local timer t = GetExpiredTimer()
  if players > 0 then
  call DisplayTextToForce(GetPlayersAll(), I2S(players))
  set players = players - 1
  else
  call DisplayTextToForce(GetPlayersAll(), "BEGIN!")
  call RecTimer(t)
  call PauseAllUnits(false)
  endif
  set t = null
  endfunction
  
  function GameWillStartIn takes nothing returns nothing
  local timer t = GetFreeTimer()
  set players = 2
  call DisplayTextToForce(GetPlayersAll(), "Game will start in:")
  call DisplayTextToForce(GetPlayersAll(), "3")
  call TimerStart(t, 1.00, true, function ShowMsg)
  set t = null  
  endfunction

  function OnButtonClick takes nothing returns boolean
  local button b = GetClickedButton()
  local integer i
  local integer temp
  if b == no_meteorites then
  set votes[1] = votes[1] + 1
  elseif b == normal then
  set votes[2] = votes[2] + 1
  elseif b == hard then
  set votes[3] = votes[3] + 1
  elseif b == nightmare then
  set votes[4] = votes[4] + 1
  elseif b == hell then
  set votes[5] = votes[5] + 1
  else
  set votes[2] = votes[2] + 1
  set votes[0] = votes[0] + 1
  endif
  set players = players - 1
  if players == 0 then
  if votes[0] > players_total/2 then
  call ModeMsg(0)
  endif
  set i = 1
  set temp = 0
  loop
  exitwhen i > 5
  if votes[i] > temp then
  set temp = votes[i]
  set udg_mode = i
  endif
  set i = i + 1
  endloop
  call ModeMsg(udg_mode)
  call GameWillStartIn()
  call RecTimer(t)
  call DialogDestroy(mode_window)
  set mode_window = null
  set t = null
  endif
  return false
  endfunction

  private function OnExpire takes nothing returns nothing
  local integer i = 0
  local integer temp
  call RecTimer(GetExpiredTimer())
  set t = null
  loop
  exitwhen i > 11
  call DialogDisplay(Player(i), mode_window, false)
  set i = i + 1
  endloop
  call DialogDestroy(mode_window)
  set votes[2] = votes[2] + players
  if votes[0] > players_total/2 then
  call ModeMsg(0)
  endif
  set i = 1
  set temp = 0
  loop
  exitwhen i > 5
  if votes[i] > temp then
  set temp = votes[i]
  set udg_mode = i
  endif
  set i = i + 1
  endloop
  call ModeMsg(udg_mode)
  call GameWillStartIn()
  endfunction

  function Trig_Dialog_Actions takes nothing returns boolean
  local integer i = 0
  local trigger tr = CreateTrigger()
  call TimerStart(t, 20.00, false, function OnExpire)
  call DisplayTextToForce(GetPlayersAll(), "You have 20 seconds to choose mode")
  call DialogSetMessage( mode_window, "Choose mode:" )
  set no_meteorites = DialogAddButton( mode_window, "No Meteorites", 1 )
  set normal = DialogAddButton( mode_window, "Normal", 2 )
  set hard = DialogAddButton( mode_window, "Hard", 3 )
  set nightmare = DialogAddButton( mode_window, "Nightmare", 4 )
  set hell = DialogAddButton( mode_window, "Hell", 5 )
  set test = DialogAddButton( mode_window, "Test", 0 )
  loop
  exitwhen i > 11
  if GetPlayerController(Player(i)) == MAP_CONTROL_USER and GetPlayerSlotState(Player(i)) == PLAYER_SLOT_STATE_PLAYING then
  set players = players + 1
  set players_total = players_total + 1
  call DialogDisplay( Player(i), mode_window, true )
  endif
  set i = i + 1
  endloop
  call TriggerRegisterDialogEventBJ( tr, mode_window )
  call TriggerAddCondition( tr, Condition( function OnButtonClick ) )
  set tr = null
  call PauseAllUnits(true)
  return false
  endfunction

//===========================================================================
  function InitTrig_Mode takes nothing returns nothing
  set gg_trg_Mode = CreateTrigger(  )
  call TriggerRegisterTimerEventSingle( gg_trg_Mode, 0.00 )
  call TriggerAddCondition( gg_trg_Mode, Condition(function Trig_Dialog_Actions) )
  set votes[0] = 0
  set votes[1] = 0
  set votes[2] = 0
  set votes[3] = 0
  set votes[4] = 0
  set votes[5] = 0
  endfunction
  
endscope

EDIT: By the way.. the forum used to copy-paste spaces/tabs from my scripts before, but not anymore.... it looks ugly and confusing now.
Is there any way I can paste the tabs/spaces, without manually fixing my script after posting??
 
Level 3
Joined
Aug 24, 2016
Messages
27
If it wasn't clear from my previous post, the culprit which ruined everything turned out to be that "Set dSelection = NewDialog()", which I guessed thanks to pOke's post, as he mentions "NewDialog()" function not being present in his editor, which led me to believe that "NewDialog()" was some sort of NewGen innovation that didn't work. Which turned out to be true, because as soon as I deleted it - everything started working just fine.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,287
The trigger does not work because you are attaching the event to "null" dialog. Events are attached at map initialization where as you create the dialog 1 second after the game begins. Hence the event is attached to a null/default value dialog and not your created dialog.

The solution is to attach the event after the dialog is created using the event attachment action.
 
Level 3
Joined
Aug 24, 2016
Messages
27
The trigger does not work because you are attaching the event to "null" dialog. Events are attached at map initialization where as you create the dialog 1 second after the game begins. Hence the event is attached to a null/default value dialog and not your created dialog.

The solution is to attach the event after the dialog is created using the event attachment action.
Nope, it's not :)
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,287
Nope, it's not
Except it is, you even admitted it...
If it wasn't clear from my previous post, the culprit which ruined everything turned out to be that "Set dSelection = NewDialog()", which I guessed thanks to pOke's post, as he mentions "NewDialog()" function not being present in his editor, which led me to believe that "NewDialog()" was some sort of NewGen innovation that didn't work. Which turned out to be true, because as soon as I deleted it - everything started working just fine.
You were creating, filling and displaying a new dialog which is different from the one the event was attached to. Hence the event would not fire for that dialog.

There is a reason that such a function does not exist in standard GUI.
 
Level 3
Joined
Aug 24, 2016
Messages
27
Except it is, you even admitted it...

You were creating, filling and displaying a new dialog which is different from the one the event was attached to. Hence the event would not fire for that dialog.

There is a reason that such a function does not exist in standard GUI.
Why would I go the long way you suggested if I can (and I did) just delete that "NewDialog()" thingy, and everything starts working like it is supposed to?
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,287
Why would I go the long way you suggested if I can (and I did) just delete that "NewDialog()" thingy, and everything starts working like it is supposed to?
I only really know JASS because WC3 GUI is really terrible to use. As such I was not particularly aware that was a non-standard GUI function and I was not aware that the GUI variable editor also kindly created a dialog for one to use. That said, when dealing with dialogs in JASS none of this magic happens automatically and instead you need to make sure to both create the dialog and to attach the dialog events to a trigger after the dialog's creation.

WereElf's code shows this off, where he declare initializes a dialog and then later attaches dialog events for it to a trigger.
 
Status
Not open for further replies.
Top