• Check out the results of the Techtree Contest #19!
  • 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.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

[JASS] Jass and Dialog boxes

Status
Not open for further replies.
Level 3
Joined
Jul 29, 2006
Messages
61
I'm attempting to write a script in Jass (Preferably a single trigger). The script will activate every 4 levels, and display a dialog box. This Dialog box has three buttons, one for each stat, and when one is clicked that stat should increase by one.
Here is the code I have made so far.
JASS:
function Increase takes unit leveler, button Str, button Agi, button Int returns nothing
    if (GetClickedButtonBJ == Str) then
        call ModifyHeroStat( bj_HEROSTAT_STR, leveler, bj_MODIFYMETHOD_ADD, 1 )
    endif
    if (GetClickedButtonBJ == Agi) then
        call ModifyHeroStat( bj_HEROSTAT_AGI, leveler, bj_MODIFYMETHOD_ADD, 1 )
    endif
    if (GetClickedButtonBJ == Int) then
        call ModifyHeroStat( bj_HEROSTAT_INT, leveler, bj_MODIFYMETHOD_ADD, 1 )
    endif
    leveler = null
    Str = null
    Agi = null
    Int = null
endfunction

function StatIncrease takes unit leveler returns nothing
    local dialog Dialog
    local button Strength
    local button Agility
    local button Intelligence
    call DialogSetMessageBJ( Dialog, "Choose Which Stat to Increase" )
    set Strength = call DialogAddButtonBJ( Dialog, "Strength" )
    set Agility = call DialogAddButtonBJ( Dialog, "Agility" )
    set Intelligence = call DialogAddButtonBJ( Dialog, "Intelligence" )
    call DialogDisplayBJ( true, Dialog, GetOwningPlayer(leveler) )
    
    //Function to detect which Button is pressed
    
    call DialogClearBJ( Dialog )
    call Increase( leveler, Strength, Agility, Intelligence)
    Dialog = null
    Strength = null
    Agility = null
    Intelligence = null
endfunction

function Trig_StatIncrease_Conditions takes nothing returns boolean
    if ( not ( ModuloInteger(GetHeroLevel(GetTriggerUnit()), 4) == 0 ) ) then
        return false
    endif
    return true
endfunction

function Trig_StatIncrease_Actions takes nothing returns nothing
    local unit leveler
    set leveler = GetLevelingUnit
    call StatIncrease( leveler )
    set leveler = null
endfunction

//===========================================================================
function InitTrig_StatIncrease takes nothing returns nothing
    set gg_trg_StatIncrease = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_StatIncrease, EVENT_PLAYER_HERO_LEVEL )
    call TriggerAddCondition( gg_trg_StatIncrease, Condition( function Trig_StatIncrease_Conditions ) )
    call TriggerAddAction( gg_trg_StatIncrease, function Trig_StatIncrease_Actions )
endfunction

Any help would be greatly appreciated.
 
Alright, I was hit with a burst of inspiration and changed the script, now I have one little problem. (new script:)
JASS:
function StrIncrease takes unit leveler returns nothing
    call ModifyHeroStat( bj_HEROSTAT_STR, leveler, bj_MODIFYMETHOD_ADD, 1 )
    set leveler = null
endfunction

function AgiIncrease takes unit leveler returns nothing
    call ModifyHeroStat( bj_HEROSTAT_STR, leveler, bj_MODIFYMETHOD_ADD, 1 )
    set leveler = null
endfunction

function IntIncrease takes unit leveler returns nothing
    call ModifyHeroStat( bj_HEROSTAT_STR, leveler, bj_MODIFYMETHOD_ADD, 1 )
    set leveler = null
endfunction

function StatIncrease takes unit leveler returns nothing
    local dialog Dialog = DialogCreate()
    local button Strength
    local button Agility
    local button Intelligence
    local trigger s = CreateTrigger()
    local trigger a = CreateTrigger()
    local trigger i = CreateTrigger()
    
    call DialogSetMessage( Dialog, "Choose Which Stat to Increase" )
    set Strength = DialogAddButton( Dialog, "Strength", 0 )
    set Agility = DialogAddButton( Dialog, "Agility", 0 )
    set Intelligence = DialogAddButton( Dialog, "Intelligence", 0 )
    call DialogDisplay( GetOwningPlayer(leveler), Dialog, true )
    
    call TriggerRegisterDialogButtonEvent( s, Strength)
    call TriggerAddAction( s, StrIncrease(leveler))
    call DestroyTrigger( s )
    
    call TriggerRegisterDialogButtonEvent( a, Agility)
    call TriggerAddAction( a, AgiIncrease(leveler)) 
    call DestroyTrigger( a )
    
    call TriggerRegisterDialogButtonEvent( i, Intelligence)
    call TriggerAddAction( i, IntIncrease(leveler))
    call DestroyTrigger( i )
     
    call DialogDestroy( Dialog )
    set Strength = null
    set Agility = null
    set Intelligence = null
endfunction

function Trig_StatIncrease_Conditions takes nothing returns boolean
    if ( not ( ModuloInteger(GetHeroLevel(GetTriggerUnit()), 4) == 0 ) ) then
        return false
    endif
    return true
endfunction

function Trig_StatIncrease_Actions takes nothing returns nothing
    local unit leveler = GetLevelingUnit()
    call StatIncrease( leveler )
    set leveler = null
endfunction

//===========================================================================
function InitTrig_StatIncrease takes nothing returns nothing
    set gg_trg_StatIncrease = CreateTrigger( )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_StatIncrease, EVENT_PLAYER_HERO_LEVEL )
    call TriggerAddCondition( gg_trg_StatIncrease, Condition( function Trig_StatIncrease_Conditions ) )
    call TriggerAddAction( gg_trg_StatIncrease, function Trig_StatIncrease_Actions )
endfunction
When I try to compile I get this error
Compile error line11384: Invalid argument type (void)
call DestroyTrigger( s )
Compile error line11384: Invalid argument type (void)
call DestroyTrigger( a )
Compile error line11384: Invalid argument type (void)
call DestroyTrigger( i )
These should not be voids, any idea why they are considered so?
 
to GhostWolf: read the trigger carefully he created the triggers

to gralamin: you need a handle attachment system for that
there is no
TriggerAddAction(trig,function bla(a))
there is TriggerAddAction(trig, function bla)
get used to it
 
It doesn't allow you to pass parameters through a function pointer. (As Need 02 said)
This:
JASS:
call TriggerAddAction( s, StrIncrease(leveler))
Needs to be this:
JASS:
call TriggerAddAction( s, function StrIncrease)
 
I had thought I might need to use handles, I have never quite gotten use to them, but I'll see if I can figure it out.

Just add states like you did in the previous code.
What exactly do you mean? How would I add states depending on which dialog button is pressed?

Edit:
Alright, I managed to make the thing compile using local handle vars, and I now just have an error with the dialog boxes popping up (it doesn't display anything). In addition, any sort of way of improving performance would help. Thanks.

JASS:
function StrIncrease takes nothing returns nothing
    local trigger tr = GetTriggeringTrigger()
    local unit leveler = GetHandleUnit(tr, "LevelingUnit")
    call ModifyHeroStat( bj_HEROSTAT_STR, leveler, bj_MODIFYMETHOD_ADD, 1 )
    call FlushHandleLocals(tr)
    call DestroyTrigger( tr )
    set leveler = null
endfunction

function AgiIncrease takes nothing returns nothing
    local trigger tr = GetTriggeringTrigger()
    local unit leveler = GetHandleUnit(tr, "LevelingUnit")
    call ModifyHeroStat( bj_HEROSTAT_AGI, leveler, bj_MODIFYMETHOD_ADD, 1 )
    call FlushHandleLocals(tr)
    call DestroyTrigger( tr )
    set leveler = null
endfunction

function IntIncrease takes nothing returns nothing
    local trigger tr = GetTriggeringTrigger()
    local unit leveler = GetHandleUnit(tr, "LevelingUnit")
    call ModifyHeroStat( bj_HEROSTAT_INT, leveler, bj_MODIFYMETHOD_ADD, 1 )
    call FlushHandleLocals(tr)
    call DestroyTrigger( tr )
    set leveler = null
endfunction

function StatIncrease takes unit leveler returns nothing
    local dialog Dialog = DialogCreate()
    local button Strength
    local button Agility
    local button Intelligence
    local trigger t = CreateTrigger()
    
    call DialogSetMessage( Dialog, "Choose Which Stat to Increase" )
    set Strength = DialogAddButton( Dialog, "Strength", 0 )
    set Agility = DialogAddButton( Dialog, "Agility", 0 )
    set Intelligence = DialogAddButton( Dialog, "Intelligence", 0 )
    call DialogDisplay( GetOwningPlayer(leveler), Dialog, true )
    
    call SetHandleHandle(leveler, "LevelingUnit", t)
    
    call TriggerRegisterDialogButtonEvent( t, Strength )
    call TriggerAddAction( t, function StrIncrease )
    
    set t = CreateTrigger()  // Different trigger, new var
    call SetHandleHandle(leveler, "LevelingUnit", t)
    call TriggerRegisterDialogButtonEvent( t, Agility)
    call TriggerAddAction( t, function AgiIncrease)

    set t = CreateTrigger()
    call SetHandleHandle(leveler, "LevelingUnit", t)
    call TriggerRegisterDialogButtonEvent( t, Intelligence)
    call TriggerAddAction( t, function IntIncrease)
    
    call DialogClear(Dialog)
    call DialogDestroy( Dialog )
    set Strength = null
    set Agility = null
    set Intelligence = null
endfunction

function Trig_StatIncrease_Conditions takes nothing returns boolean
    if ( not ( ModuloInteger(GetHeroLevel(GetTriggerUnit()), 4) == 0 ) ) then
        return false
    endif
    return true
endfunction

function Trig_StatIncrease_Actions takes nothing returns nothing
    local unit leveler = GetLevelingUnit()
    call StatIncrease( leveler )
    set leveler = null
endfunction

//===========================================================================
function InitTrig_StatIncrease takes nothing returns nothing
    set gg_trg_StatIncrease = CreateTrigger( )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_StatIncrease, EVENT_PLAYER_HERO_LEVEL )
    call TriggerAddCondition( gg_trg_StatIncrease, Condition( function Trig_StatIncrease_Conditions ) )
    call TriggerAddAction( gg_trg_StatIncrease, function Trig_StatIncrease_Actions )
endfunction
 
Last edited:
My guess after mulling it over is the destroy dialog command is executing while the dialog is being displayed. I removed the clear and dialog destroy command and now it works. However doesn't that leak?

Edit: Is there any way to make a SetHandleDialog or GetHandleDialog functions? Or is a Dialog a Handle?

And now I have a script that does not increase the actual stats. Any idea why?
(new Script)
Edit: Hopefully Leakless version
JASS:
function StrIncrease takes nothing returns nothing
    local trigger tr = GetTriggeringTrigger()
    local unit leveler = GetHandleUnit(tr, "LevelingUnit")
    local dialog Dialog = GetHandleDialog(tr, "StatIncrease")
    call ModifyHeroStat( 0, leveler, 0, 1 )
    call DestroyTrigger(GetHandleTrigger(tr, "AgilityIncrease"))
    call DestroyTrigger(GetHandleTrigger(tr, "IntelligenceIncrease"))
    call FlushHandleLocals(tr)
    call DestroyTrigger( tr )
    call DialogClear(Dialog)
    call DialogDestroy(Dialog)
    set leveler = null
    set Dialog = null
endfunction

function AgiIncrease takes nothing returns nothing
    local trigger tr = GetTriggeringTrigger()
    local unit leveler = GetHandleUnit(tr, "LevelingUnit")
    local dialog Dialog = GetHandleDialog(tr, "StatIncrease")
    call ModifyHeroStat( 1, leveler, 0, 1 )
    call DestroyTrigger(GetHandleTrigger(tr, "StrengthIncrease"))
    call DestroyTrigger(GetHandleTrigger(tr, "IntelligenceIncrease"))
    call FlushHandleLocals(tr)
    call DestroyTrigger( tr )
    call DialogClear(Dialog)
    call DialogDestroy(Dialog)
    set leveler = null
    set Dialog = null
endfunction

function IntIncrease takes nothing returns nothing
    local trigger tr = GetTriggeringTrigger()
    local unit leveler = GetHandleUnit(tr, "LevelingUnit")
    local dialog Dialog = GetHandleDialog(tr, "StatIncrease")
    call ModifyHeroStat( 2, leveler, 0, 1 )
    call DestroyTrigger(GetHandleTrigger(tr, "AgilityIncrease"))
    call DestroyTrigger(GetHandleTrigger(tr, "StrengthIncrease"))
    call FlushHandleLocals(tr)
    call DestroyTrigger( tr )
    call DialogClear(Dialog)
    call DialogDestroy(Dialog)
    set leveler = null
    set Dialog = null
endfunction

function StatIncrease takes unit leveler returns nothing
    local dialog Dialog = DialogCreate()
    local button Strength
    local button Agility
    local button Intelligence
    local trigger t = CreateTrigger()
    
    call DialogSetMessage( Dialog, "Choose Which Stat to Increase" )
    set Strength = DialogAddButton( Dialog, "Strength", 0 )
    set Agility = DialogAddButton( Dialog, "Agility", 0 )
    set Intelligence = DialogAddButton( Dialog, "Intelligence", 0 )
    call DialogDisplay( GetOwningPlayer(leveler), Dialog, true )
    
    call SetHandleHandle(leveler, "LevelingUnit", t)
    call SetHandleHandle(Dialog, "StatIncrease", t)
    
    call TriggerRegisterDialogButtonEvent( t, Strength )
    call TriggerAddAction( t, function StrIncrease )
    call SetHandleHandle(t, "StrengthUp", leveler)
    
    set t = CreateTrigger()  // Different trigger, new var
    call SetHandleHandle(leveler, "LevelingUnit", t)
    call TriggerRegisterDialogButtonEvent( t, Agility)
    call TriggerAddAction( t, function AgiIncrease)
    call SetHandleHandle(t, "AgilityUp", leveler)

    set t = CreateTrigger()
    call SetHandleHandle(leveler, "LevelingUnit", t)
    call TriggerRegisterDialogButtonEvent( t, Intelligence)
    call TriggerAddAction( t, function IntIncrease)
    call SetHandleHandle(t, "IntelligenceUp", leveler)
    
    set Dialog = null
    set Strength = null
    set Agility = null
    set Intelligence = null
endfunction

function Trig_StatIncrease_Conditions takes nothing returns boolean
    if ( not ( ModuloInteger(GetHeroLevel(GetTriggerUnit()), 4) == 0 ) ) then
        return false
    endif
    return true
endfunction

function Trig_StatIncrease_Actions takes nothing returns nothing
    local unit leveler = GetLevelingUnit()
    call StatIncrease( leveler )
    set leveler = null
endfunction

//===========================================================================
function InitTrig_StatIncrease takes nothing returns nothing
    set gg_trg_StatIncrease = CreateTrigger( )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_StatIncrease, EVENT_PLAYER_HERO_LEVEL )
    call TriggerAddCondition( gg_trg_StatIncrease, Condition( function Trig_StatIncrease_Conditions ) )
    call TriggerAddAction( gg_trg_StatIncrease, function Trig_StatIncrease_Actions )
endfunction
JASS:
function GetHandleDialog takes handle subject, string name returns dialog
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction
 
Last edited:
Status
Not open for further replies.
Back
Top