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

GetClickedButton()

Status
Not open for further replies.
Level 17
Joined
Feb 11, 2011
Messages
1,860
Hello,

I have something like this:

JASS:
globals
    private dialog d
    private button array b
endglobals

private function ClickButton takes nothing returns boolean
    if (GetClickedButton() == b[0]) then
        call BJDebugMsg("Button 0 clicked!")
    else
        call BJDebugMsg("Something else")
    endif
    
    return false
endfunction

private function CreateDialog takes nothing returns boolean
    local trigger t = CreateTrigger()
    
    set d = DialogCreate()
    call DialogSetMessage(d, "Click a button::")
    
    set b[0] = DialogAddButton(d, "Button 0", 0)
    set b[1] = DialogAddButton(d, "Button 1", 0)
    set b[2] = DialogAddButton(d, "Button 2", 0)

    call TriggerAddCondition(t, Condition(function ClickButton))
    call TriggerRegisterDialogButtonEvent(t, b[0])
    call TriggerRegisterDialogButtonEvent(t, b[1])
    call TriggerRegisterDialogButtonEvent(t, b[2])
    call DialogDisplay(Player(0), d, true)
    
    set t = null
    return false
endfunction

private function onInit takes nothing returns nothing
    local trigger t = CreateTrigger()
    
    call TriggerAddCondition(t, Condition(function CreateDialog))
    call TriggerRegisterTimerEvent(t, 0.01, false)
    
    set t = null
endfunction

When I test it and click the first button (with text "Button 0"), it displays the text "Something else" instead of "Button 0 clicked!". What am I doing wrong? Perhaps I am missing something, but I can't find it.

Thanks,

Mr_Bean
 
Level 17
Joined
Feb 11, 2011
Messages
1,860
I tried changing the TriggerRegisterDialogButtonEvent(t, b[0])-events with call TriggerRegisterDialogEvent(t, d) and it worked.

Hmmm, interesting. I will give it a try. Thanks.

I do not have an explanation why your method doesn't work though. Do you really need separate events for each button?

No, I don't need separate events, I wasn't aware of that function you used :wink:
I don't work with dialogs and buttons often, so this is probably the reason.

Thanks for the help!
 
I do not have an explanation why your method doesn't work though. Do you really need separate events for each button?

If I recall correctly, GetClickedButton() will return null with the dialog button event, so that is most likely why it is not working. (either a bug or Blizzard figured that people wouldn't use that event unless they already knew which button was being clicked) As you've said, he should just use the other event.
 
Status
Not open for further replies.
Top