PDA

View Full Version : [JASS] Dialog and DialogButtons


wiredbomb0
08-21-2012, 06:16 AM
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:

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

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?

WaterKnight
08-21-2012, 07:25 AM
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.

wiredbomb0
08-21-2012, 07:52 AM
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?

WaterKnight
08-21-2012, 09:25 AM
Either do not replace the dialog or create the event via jass afterwards.

wiredbomb0
08-21-2012, 10:06 AM
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.