HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Problem(s) with dialog(s)

04-23-2009, 01:01 AM#1
darkwulfv
So, I'm relatively new at using Dialog windows, so...

Collapse JASS:
function Upgrade_Purchase_Actions takes nothing returns nothing
  local integer i = GetPlayerId(GetOwningPlayer(GetTriggerUnit()))
  local integer id = GetItemTypeId(GetManipulatedItem())
  local integer lvl
  
  call BJDebugMsg("Called")
  
  //Troop Upgrade
  if id == 'I000' then
    set lvl = GetPlayerTechCount(Player(i), 'R001', false)
    if lvl < 3 then
      call DialogDisplay(Player(i), Upgrades[i], true)
      call DialogSetMessage(Upgrades[i], "Buy Troop Upgrade level " + I2S(lvl+1) + " for " + I2S(250 + (lvl * 100)) + " gold?")
      set YesTroop = DialogAddButton(Upgrades[i], "Yes!", 1)
      set No = DialogAddButton(Upgrades[i], "Nope.", 2)
    endif
.........
endfunction

The "Called" comes up on screen, but no dialog ever shows. Is there a reason for this?
(DialogDisplay(...) used to be right before the endif, but it didn't show up then either.)
Notes:
YesTroop/No are buttons, Upgrades[i] is an array of dialogs. I made it an array so that each player had their own in case 2 players purchased upgrades at the same time, but at different levels/upgrades.

Do Dialogs need to be initialized in some way beforehand?
04-23-2009, 01:31 AM#2
Feroc1ty
You should add other debug messages aswell, such as after the items is used, and after it checks if lvl is higher than 3.

Also, I'm pretty sure you need to add the buttons to a dialog before you display it.
04-23-2009, 01:43 AM#3
Anopob
Quote:
Originally Posted by Feroc1ty
You should add other debug messages aswell, such as after the items is used, and after it checks if lvl is higher than 3.

Also, I'm pretty sure you need to add the buttons to a dialog before you display it.
Yes. If that doesn't work, are you sure your conditions are true?
04-23-2009, 03:12 AM#4
darkwulfv
Quote:
Originally Posted by Feroc1ty
Also, I'm pretty sure you need to add the buttons to a dialog before you display it.
Quote:
Originally Posted by Me
(DialogDisplay(...) used to be right before the endif, but it didn't show up then either.)
It was, but I moved it. However I may have moved it after i made changes that may have been stopping it before... we'll see.

And yes, the conditions are true. It makes it at least to the checks for item and levels, and I've checked that 100 times over.
04-23-2009, 03:56 AM#5
fX_
either the higher conditions (id == 'I000' and/or 'lvl < 3') are not met or Upgrades[i] is null.

rest of the code involved with settingup Upgrades[i], as well as your method of testing this code posted here?
04-23-2009, 04:02 AM#6
darkwulfv
That's all the code involved with setting up Upgrades[i], and for testing I just purchased the item. Nothing happened. I'll do some more tweaking and test some more soon.
04-23-2009, 08:05 AM#7
fX_
if thats all the code etc etc... then you need to create a dialog for each instance in Upgrades[]

Collapse JASS:
DialogCreate
04-24-2009, 05:07 AM#8
darkwulfv
So, I'm back with more problems.

The dialog now shows up just fine. The problem is that the trigger that runs when a button is pressed... never runs. I even removed the condition so that no matter what button was pressed it would run. It didn't.

The code for the dialog's prep is:
Collapse JASS:
  if id == 'I000' then
    set lvl = GetPlayerTechCount(Player(i), 'R001', false)
    if lvl < 3 then
      call DialogSetMessage(Upgrades[i], "Buy Troop Upgrade level " + I2S(lvl+1) + " for " + I2S(250 + (lvl * 100)) + " gold?")
      set YesTroop = DialogAddButton(Upgrades[i], "Yes!", 1)
      set No = DialogAddButton(Upgrades[i], "Nope.", 2)
      call DialogDisplay(Player(i), Upgrades[i], true)
    endif
Yes, they were initialized (as per above).

Here's the first set I'm trying to get it to work for:
Collapse JASS:
//function Troop_Conditions takes nothing returns boolean
  // return GetClickedButton() == YesTroop
//endfunction

function Troop_Actions takes nothing returns nothing
  local player p = GetTriggerPlayer()
  local integer id = GetPlayerId(p)
  local integer lvl = GetPlayerTechCount(p, 'R001', false)
  
  call BJDebugMsg("Troop Called")
  
  call DialogDisplay(p, Upgrades[id], false)
  call DialogClear(Upgrades[id])
  
  if GetClickedButton() == YesTroop then
  if GetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD) >= 250 + (lvl * 100) then
  call BJDebugMsg("Doing stuff")
    call SetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD) - (250+(lvl*100)))
    call SetPlayerTechResearched(p, 'R001', lvl + 1)
    call DisplayTextToPlayer(p, 0., 0., "You have upgraded your troops' weapons and armor.")
  else
    call CS_Error(p, "You don't have enough gold!")
  endif
  endif
  
  set p = null
endfunction

//===========================================================================
function InitTrig_Troop takes nothing returns nothing
  local trigger t = CreateTrigger(  )
  local integer i = 0
  
  loop
  exitwhen i > 9
    call TriggerRegisterDialogEvent(t, Upgrades[i])
    set i = i + 1
  endloop
  
  //call TriggerAddCondition(t, Condition( function Troop_Conditions ) )
  call TriggerAddAction(t, function Troop_Actions )
  set t = null
endfunction

Neither of the BJDebugMsg's ever show up. Any idea what's going on/Going wrong?
04-24-2009, 05:50 AM#9
fX_
TriggerRegisterDialogEvent 'registers' off a dialog object. maybe your dialogs for Upgrades[] are not yet created when that init function that sets up those triggers is called - such that there are no objects to register off and the trigger never runs (no agent).

if this is the case, create the dialogs before running that function; create dialog objects for which events will be registered to the triggers.
04-24-2009, 11:34 AM#10
darkwulfv
It looks like moving the initialization for the dialogs into the InitTrig for the first button-register loop seemed to have fixed things.
04-24-2009, 11:53 AM#11
fX_
Quote:
create the dialogs before running that function
(or before the stuff in that function are called, generally.)
04-24-2009, 02:36 PM#12
PurplePoot
By the way, dialog button hotkeys are ASCII, so I doubt you want 1 and 2.
04-25-2009, 12:40 AM#13
darkwulfv
It's just a yes/no, i'm not very concerned about hotkeying.