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

[JASS] Dialogs

Status
Not open for further replies.
Level 4
Joined
Mar 23, 2009
Messages
78
I use a dialog in my custom ability training system to "forget" abilities. This leaks hard, i do not know how to fix the leaks. Here's the code of my triggers.
This one is responsible for dialog creation:
JASS:
function Trig_ForgetAbility_Conditions takes nothing returns boolean
    if ( not ( GetItemTypeId(GetSoldItem()) == 'I017' ) ) then
        return false
    endif
    return true
endfunction
function Trig_ForgetAbility_Actions takes nothing returns nothing
    local integer i=0
    local integer j=GetPlayerId(GetOwningPlayer(GetBuyingUnit()))
    set udg_Dialog[j]=DialogCreate()
    call DialogClear(udg_Dialog[j])
    call DialogSetMessage(udg_Dialog[j],"Decrease level:")
    loop
        exitwhen i==5
        if i<=3 then
            if udg_AB_SYS_HeroSkills[(j*4)+i]!=0 then
                set udg_DialogButton[(j*4)+i]=DialogAddButton(udg_Dialog[j],GetObjectName(udg_AB_SYS_HeroSkills[(j*4)+i]),0)
            endif
        endif
        if i==4 then
            set udg_DialogButton[33]=DialogAddButton(udg_Dialog[j],"Cancel",0)
        endif
        set i=i+1
    endloop
    call TriggerRegisterDialogEvent( gg_trg_ForgetAbilityButtonClick, udg_Dialog[j] ) //sys doesnt work properly w/o that
    call RemoveItem(GetSoldItem())
    call DialogDisplay(Player(j),udg_Dialog[j],true)
endfunction
function InitTrig_ForgetAbility takes nothing returns nothing
    set gg_trg_ForgetAbility = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_ForgetAbility, EVENT_PLAYER_UNIT_SELL_ITEM )
    call TriggerAddCondition( gg_trg_ForgetAbility, Condition( function Trig_ForgetAbility_Conditions ) )
    call TriggerAddAction( gg_trg_ForgetAbility, function Trig_ForgetAbility_Actions )
endfunction
and this one for catching the click on a button:
JASS:
function Trig_ForgetAbilityButtonClick_Actions takes nothing returns nothing
    local button b=GetClickedButton()
    local integer i=0
    local integer j
    local integer q=0
    loop
        exitwhen i>7
        set j=0
        loop
            exitwhen j>4
            if b==udg_DialogButton[(i*4)+j] then
                set q=GetUnitAbilityLevel(udg_Hero[i],udg_AB_SYS_HeroSkills[(i*4)+j])
                if q>1 then
                    call SetUnitAbilityLevel(udg_Hero[i],udg_AB_SYS_HeroSkills[(i*4)+j],q-1)
                else
                    call UnitRemoveAbility(udg_Hero[i],udg_AB_SYS_HeroSkills[(i*4)+j])
                    set udg_AB_SYS_HeroSkills[(i*4)+j]=0
                endif
                set q=0
                loop
                    exitwhen q>900
                    if udg_AB_SYS_HeroSkills[(i*4)+j]==udg_AB_SYS_ABI[q] then
                        call SetPlayerState(Player(i),PLAYER_STATE_RESOURCE_LUMBER,GetPlayerState(Player(i),PLAYER_STATE_RESOURCE_LUMBER)+2)
                        set q=900
                    endif
                    set q=q+1
                endloop
                call DialogDestroy(udg_Dialog[i])
                set udg_Dialog[i]=null
            endif
            set j=j+1
        endloop
        set i=i+1
    endloop
    set b=null
endfunction
function InitTrig_ForgetAbilityButtonClick takes nothing returns nothing
    local integer i=0
    set gg_trg_ForgetAbilityButtonClick = CreateTrigger(  )
    loop
        exitwhen i>7
        call TriggerRegisterDialogEvent( gg_trg_ForgetAbilityButtonClick, udg_Dialog[i] )
        set i=i+1
    endloop
    call TriggerAddAction( gg_trg_ForgetAbilityButtonClick, function Trig_ForgetAbilityButtonClick_Actions )
endfunction
i have one more question. if i need to show this to 8 players, do i need arrays for 8 dialogs and 33 (4 options + "cancel") dialog buttons or 1 variable for a dialog and 5 variables for options are enough?
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
Somehow this looks a lot like a converted GUI-trigger with some extra stuff like locals.
Anyway, I don't see any leaks (maybe I'm just missing it though). I also don't understand why you say it's leaking hard, yet you cannot fix the leaks. If you see a leak, you're most likely able to fix it.

1 dialog with 5 buttons is enough.
 
Level 4
Joined
Mar 23, 2009
Messages
78
yeah, looks similar cause my jngp doesnt work correctly with globals.
there're 6 objects created each time the dialog's shown.
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
Well, it's actually the condition which looks very GUI-like, but whatever.

What do you mean with "objects"? Dialog buttons? If so, that's a bug, not a leak.

Another thing is that you don't need to check "if i <= 3" and "if i == 4".
Remove those conditions and put set udg_DialogButton[33]=DialogAddButton(udg_Dialog[j],"Cancel",0) out of the loop.
 
Level 4
Joined
Mar 23, 2009
Messages
78
no, i use a trigger to count new handles, so after calling a dialog there appear some new. if handles appear over and over - it's a leak. btw, i changed the code after iyour notice, only 4 leak now)
 
Status
Not open for further replies.
Top