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

[vJASS] Dialog Issues

Status
Not open for further replies.
Level 17
Joined
Feb 11, 2011
Messages
1,860
I am trying the create a dialog system for choosing the difficulty and game mode. However, it doesn't work! Here are the scripts:

JASS:
globals
    dialog Dialog
    button array Button
endglobals

JASS:
function DifficultyDialog takes nothing returns nothing
    set Dialog = DialogCreate()
    call DialogClear(Dialog)
    call DialogSetMessage(Dialog, "Select Difficulty")
    set Button[1] = DialogAddButton(Dialog, "Easy", 0)
    set Button[2] = DialogAddButton(Dialog, "Normal", 0)
    set Button[3] = DialogAddButton(Dialog, "Hard", 0)
    call DialogDisplay(Player(0), Dialog, true)
endfunction

JASS:
library Dialog initializer InitTrigger

    private function Actions takes nothing returns nothing
        call DisableTrigger(GetTriggeringTrigger())
        if GetClickedButton() == Button[1] then
            set Game_Difficulty = "Easy"
        elseif GetClickedButton() == Button[2] then
            set Game_Difficulty = "Normal"
            call BJDebugMsg("Normal selected.")
        elseif GetClickedButton() == Button[3] then
            set Game_Difficulty = "Hard"
        endif
        call DialogClear(Dialog)
        call DialogSetMessage(Dialog, "Choose Game Mode")
        set Button[4] = DialogAddButton(Dialog, "Normal", 0)
        set Button[5] = DialogAddButton(Dialog, "No Special Creeps", 0)
        set Button[6] = DialogAddButton(Dialog, "No Bosses", 0)
        call DialogDisplay(Player(0), Dialog, true)
    endfunction

    private function InitTrigger takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterDialogButtonEvent(t, Button[1])
        call TriggerRegisterDialogButtonEvent(t, Button[2])
        call TriggerRegisterDialogButtonEvent(t, Button[3])
        call TriggerAddAction(t, function Actions)
        set t = null
    endfunction

endlibrary

What happens: The first dialog creates successfully. However, when I click Button[2], it should display the text "Normal selected" and create a new dialog for game mode selection, but it doesn't.

Any ideas?
 
Level 17
Joined
Feb 11, 2011
Messages
1,860
I originally had it that way but I changed it in the hope it would work. Should I use GetClickedDialog() or GetClickedButton()? Neither seem to work...

JASS:
library Dialogs initializer InitTrigger

    private function Actions takes nothing returns nothing
        call DisableTrigger(GetTriggeringTrigger())
        if GetClickedDialog() == Button[1] then
            set Game_Difficulty = "Easy"
            call EnableTrigger(gg_trg_Easy_GPS)
            call ForForce(bj_FORCE_ALL_PLAYERS, function Easy_Gold_Actions)
        elseif GetClickedDialog() == Button[2] then
            set Game_Difficulty = "Normal"
            call EnableTrigger(gg_trg_Normal_GPS)
            call BJDebugMsg("Normal selected.")
        elseif GetClickedDialog() == Button[3] then
            set Game_Difficulty = "Hard"
            call ForForce(bj_FORCE_ALL_PLAYERS, function Hard_Gold_Actions)
        endif
        call DialogClear(Dialog)
        call DialogSetMessage(Dialog, "Choose Game Mode")
        set Button[4] = DialogAddButton(Dialog, "Normal", 0)
        set Button[5] = DialogAddButton(Dialog, "No Special Creeps", 0)
        set Button[6] = DialogAddButton(Dialog, "No Bosses", 0)
        call DialogDisplay(Player(0), Dialog, true)
    endfunction

    private function Conditions takes nothing returns boolean
        if GetClickedDialog() == Button[1] or GetClickedDialog() == Button[2] then
            call Actions()
        endif
        return false
    endfunction

    private function InitTrigger takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterDialogEvent(t, Dialog)
        call TriggerAddCondition(t, Condition(function Conditions))
        set t = null
    endfunction

endlibrary
 
Level 14
Joined
Nov 18, 2007
Messages
1,084
You should be using GetClickedButton() since you're trying to compare the clicked button. There's really no point for the Conditions function, just merge what Actions does in it.

I forgot to mention this. When you create the dialog in DifficultyDialog, you need to also create the trigger there, not in InitTrigger since Dialog hasn't been created yet.
 
Status
Not open for further replies.
Top