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

[JASS] Dialog and DialogButtons

Status
Not open for further replies.
Level 2
Joined
Apr 8, 2009
Messages
21
Hey guys, I'm making a very simple system to increase a hero's attributes using stat points (you gain some per level up), anyway, I can get the main menu to fire and it loads up, however when I select a button the event doesn't even fire.

  • StatsMenu
    • Events
    • Conditions
    • Actions
      • Custom script: call StatsMenu()
      • Game - Display to (All players) the text: StatsMenu()
  • StatsAdd
    • Events
      • Dialog - A dialog button is clicked for dialogStats
    • Conditions
    • Actions
      • Game - Display to (All players) for 30.00 seconds the text: You clicked somethi...
      • Custom script: call StatsAdd()
      • Game - Display to (All players) the text: StatsAdd was called!
In my JASS section I've got:

JASS:
function StatsMenu takes nothing returns boolean
    local player p = GetTriggerPlayer()
    local unit u = udg_groupHeroes[GetPlayerId(p)]
    
    //Simple to check if the player actually owns a unit
    if u == null then
        return false
    endif
    
    //Create the Dialog
    set udg_dialogStats = DialogCreate()
    //Level %u |cffffff00%s|r
    call DialogSetMessage(udg_dialogStats,GetUnitName(u) + " - Level |cffff8000" + I2S(GetHeroLevel(u)) + "|r|nSkill Points: " + I2S(GetPlayerState(p, PLAYER_STATE_RESOURCE_FOOD_USED)))

    set udg_dialogStatsStr = DialogAddButton(udg_dialogStats, "|cffff8080Power (" + I2S(GetHeroStr(u,false)) + ")|r", 49)
    set udg_dialogStatsAgi = DialogAddButton(udg_dialogStats, "|cff80ff00Dexterity (" + I2S(GetHeroAgi(u,false)) + ")|r", 50)
    set udg_dialogStatsInt = DialogAddButton(udg_dialogStats, "|cff80ffffEssence (" + I2S(GetHeroInt(u,false)) + ")|r", 51)
    set udg_dialogStatsCancel = DialogAddButton(udg_dialogStats, "Cancel", 27)
    
    call DialogDisplay(p, udg_dialogStats, true)
    
    return true
endfunction

JASS:
function StatsAdd takes nothing returns boolean
    local button b = GetClickedButton()
    local player p = GetTriggerPlayer()
    local unit u = udg_groupHeroes[GetPlayerId(p)]
    
    //Simple to check if the player actually owns a unit
    if u == null then
        return false
    endif
    
    //Gives the user a chance to leave the window without spending any points
    if b == udg_dialogStatsCancel then
        return false
    endif
    
    //Adds points to Strength
    if b == udg_dialogStatsStr then
        call AddHeroStr(u, 1)
    endif
    if b == udg_dialogStatsAgi then
        call AddHeroAgi(u, 1)
    endif
    if b == udg_dialogStatsInt then
        call AddHeroInt(u, 1)
    endif
    
    return true
endfunction

I've got a udg_groupHeroes (unit, array) that stores the hero that each player can pick (which happens in another function) so that's where it gets all of that extra information. Even if the StatsAdd() function doesn't work, the Game - Display to ... function should still show something but I have no idea what's going on. AddHero<stat> is just another function I wrote to simplify adding stats. Any ideas why nothing is showing?
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
The events you write in GUI in the Events-block are created during initialization and if you use a variable there, not the variable itself is passed but the current value behind it.

You change the content of udg_dialogStats after the event has been created, the dialog the event is referring to is no longer the same the variable holds.

Dialog variables in GUI already get a functional dialog object as a preset value.
 
Level 2
Joined
Apr 8, 2009
Messages
21
The events you write in GUI in the Events-block are created during initialization and if you use a variable there, not the variable itself is passed but the current value behind it.

You change the content of udg_dialogStats after the event has been created, the dialog the event is referring to is no longer the same the variable holds.

Dialog variables in GUI already get a functional dialog object as a preset value.

So does this mean I can't use JASS to create a dialog and get button commands from it? Or do I have to use a command that can save a dialog between events?
 
Level 2
Joined
Apr 8, 2009
Messages
21
Either do not replace the dialog or create the event via jass afterwards.

Alright, took me a little while to understand what you had meant, but I understand perfectly now. I've got an even for map initilzation and another that's set to fire after 0.1s to create the event. Worked like a charm :) I ran the window twice and it ended up having 2x the buttons to click, but I just added in a DialogClear command in the 'when a dialog button was cleared' trigger in JASS to clear it so it's empty for the next time. Thanks for your help, I wouldn't have gotten it.
 
Status
Not open for further replies.
Top