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

Multiple triggers

Status
Not open for further replies.
Level 2
Joined
Dec 1, 2007
Messages
11
[(there may be this already, but I searched and I couldn't find anything.)]

I try to create a dialog( I am new to jass, learning it), and I try to have 2 triggers in 1 (2 event registers).
JASS:
globals
dialog dial
button array diabut
unit target
endglobals

function buttonclicked takes nothing returns nothing
local effect heal
call BJDebugMsg("gunnar")
call DialogDisplay(Player(0), dial, false)
if (GetClickedButton() == diabut[1]) then
    call BJDebugMsg("blab")
    call AddSpecialEffectTarget("Abilities\\Spells\\Human\\Heal\\HealTarget.mdl", target, "overhead")
    set heal = GetLastCreatedEffectBJ()
    call TriggerSleepAction(2)
    endif
call DestroyEffectBJ(heal)
endfunction

function dialogaction takes nothing returns nothing
set target = GetEnteringUnit()
set dial = DialogCreate()
call DialogSetMessage(dial, "test")
call DialogAddButtonBJ(dial, "Heal hero")
set diabut[1] = GetLastCreatedButtonBJ()
call DialogAddButtonBJ(dial, "Nevermind.")
set diabut[2] = GetLastCreatedButtonBJ()
call DialogDisplay(Player(0), dial, true)
endfunction

//===========================================================================

function InitTrig_Dialog takes nothing returns nothing
    local trigger trig = CreateTrigger()
    local trigger trig1 = CreateTrigger()
    call TriggerRegisterDialogEventBJ(trig1, dial)
    call TriggerRegisterEnterRectSimple(trig, gg_rct_Region_001)
    call TriggerAddAction(trig1, function buttonclicked)
    call TriggerAddAction(trig, function dialogaction)
endfunction

Don't mind about the debugmsg's, they will be replaced with functions later.
What I'm acctually wondering is if you can have multiple event functions in 1 trigger.
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
Yes, you can have multiple events in one trigger. But you should get rid of all the BJ's (the functions highlighted in red), aside from "BJDebugMessage", as it's supposed to be removed when releasing the system.
And learn to align your script.
You don't need the effect "heal", in fact: it's useless in your trigger (there is no "last created effect", it's never set).
You can set variables at the same time you do something (like "set unit1 = CreateUnit(...)").
Whenever you have to put a real somewhere (like in TriggerSleepAction), don't forget to put a point behind the number (like "2.", instead of "2").

JASS:
globals
    dialog dial
    button array diabut
    unit target
endglobals

function buttonclicked takes nothing returns nothing
    call BJDebugMsg("gunnar")
    call DialogDisplay(Player(0), dial, false)
    
    if (GetClickedButton() == diabut[1]) then
        call BJDebugMsg("blab")
        call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Human\\Heal\\HealTarget.mdl", target, "overhead"))
        call TriggerSleepAction(2.)
    endif
endfunction

function dialogaction takes nothing returns nothing
    set target = GetEnteringUnit()
    set dial = DialogCreate()
    
    call DialogSetMessage(dial, "test")
    set diabut[1] = DialogAddButton(dial, "Heal hero", 1)
    set diabut[2] = DialogAddButton(dial, "Nevermind", 2)
    call DialogDisplay(Player(0), dial, true)
endfunction

//===========================================================================

function InitTrig_Dialog takes nothing returns nothing
    local trigger trig = CreateTrigger()
    local trigger trig1 = CreateTrigger()
    
    call TriggerRegisterDialogEvent(trig1, dial)
    call TriggerRegisterEnterRectSimple(trig, gg_rct_Region_001)
    call TriggerAddAction(trig1, function buttonclicked)
    call TriggerAddAction(trig, function dialogaction)
endfunction

Some quick fixes.
 
Level 2
Joined
Dec 1, 2007
Messages
11
Yes, you can have multiple events in one trigger. But you should get rid of all the BJ's (the functions highlighted in red), aside from "BJDebugMessage", as it's supposed to be removed when releasing the system.
And learn to align your script.
You don't need the effect "heal", in fact: it's useless in your trigger (there is no "last created effect", it's never set).
You can set variables at the same time you do something (like "set unit1 = CreateUnit(...)").
Whenever you have to put a real somewhere (like in TriggerSleepAction), don't forget to put a point behind the number (like "2.", instead of "2").

JASS:
globals
    dialog dial
    button array diabut
    unit target
endglobals

function buttonclicked takes nothing returns nothing
    call BJDebugMsg("gunnar")
    call DialogDisplay(Player(0), dial, false)
    
    if (GetClickedButton() == diabut[1]) then
        call BJDebugMsg("blab")
        call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Human\\Heal\\HealTarget.mdl", target, "overhead"))
        call TriggerSleepAction(2.)
    endif
endfunction

function dialogaction takes nothing returns nothing
    set target = GetEnteringUnit()
    set dial = DialogCreate()
    
    call DialogSetMessage(dial, "test")
    set diabut[1] = DialogAddButton(dial, "Heal hero", 1)
    set diabut[2] = DialogAddButton(dial, "Nevermind", 2)
    call DialogDisplay(Player(0), dial, true)
endfunction

//===========================================================================

function InitTrig_Dialog takes nothing returns nothing
    local trigger trig = CreateTrigger()
    local trigger trig1 = CreateTrigger()
    
    call TriggerRegisterDialogEvent(trig1, dial)
    call TriggerRegisterEnterRectSimple(trig, gg_rct_Region_001)
    call TriggerAddAction(trig1, function buttonclicked)
    call TriggerAddAction(trig, function dialogaction)
endfunction

Some quick fixes.

Still doesn't work. When I enter the region, nothing pops up anymore.
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
It shows the dialog for me, and it displays the messages.

Edit: wait, I did do this though:

JASS:
globals
    dialog dial = DialogCreate()
    button array diabut
    unit target
endglobals

function buttonClicked takes nothing returns nothing
    call BJDebugMsg("gunnar")
    call DialogDisplay(Player(0), dial, false)
    
    if (GetClickedButton() == diabut[1]) then
        call BJDebugMsg("blab")
        call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Human\\Heal\\HealTarget.mdl", target, "overhead"))
        call TriggerSleepAction(2)
    endif
endfunction

function dialogAction takes nothing returns nothing
    set target = GetEnteringUnit()
    
    call DialogSetMessage(dial, "test")
    set diabut[1] = DialogAddButton(dial, "Heal hero", 1)
    set diabut[2] = DialogAddButton(dial, "Nevermind", 2)
    call DialogDisplay(Player(0), dial, true)
endfunction

//===========================================================================

function InitTrig_Dialog takes nothing returns nothing
    local trigger trig1 = CreateTrigger()
    local trigger trig2 = CreateTrigger()
    
    call TriggerRegisterDialogEvent(trig1, dial)
    call TriggerRegisterEnterRectSimple(trig2, gg_rct_Region_001)
    call TriggerAddAction(trig1, function buttonClicked)
    call TriggerAddAction(trig2, function dialogAction)
endfunction

I set up the dialog in the "globals". Forgot to add that before ;)
 
Level 2
Joined
Dec 1, 2007
Messages
11
It shows the dialog for me, and it displays the messages.

Edit: wait, I did do this though:

JASS:
globals
    dialog dial = DialogCreate()
    button array diabut
    unit target
endglobals

function buttonClicked takes nothing returns nothing
    call BJDebugMsg("gunnar")
    call DialogDisplay(Player(0), dial, false)
    
    if (GetClickedButton() == diabut[1]) then
        call BJDebugMsg("blab")
        call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Human\\Heal\\HealTarget.mdl", target, "overhead"))
        call TriggerSleepAction(2)
    endif
endfunction

function dialogAction takes nothing returns nothing
    set target = GetEnteringUnit()
    
    call DialogSetMessage(dial, "test")
    set diabut[1] = DialogAddButton(dial, "Heal hero", 1)
    set diabut[2] = DialogAddButton(dial, "Nevermind", 2)
    call DialogDisplay(Player(0), dial, true)
endfunction

//===========================================================================

function InitTrig_Dialog takes nothing returns nothing
    local trigger trig1 = CreateTrigger()
    local trigger trig2 = CreateTrigger()
    
    call TriggerRegisterDialogEvent(trig1, dial)
    call TriggerRegisterEnterRectSimple(trig2, gg_rct_Region_001)
    call TriggerAddAction(trig1, function buttonClicked)
    call TriggerAddAction(trig2, function dialogAction)
endfunction

I set up the dialog in the "globals". Forgot to add that before ;)

Hmm, still doesn't work for me.
Current script:
JASS:
globals
    dialog dial = DialogCreate()
    button array diabut
    unit target
endglobals

function buttonClicked takes nothing returns nothing
    call BJDebugMsg("gunnar")
    call DialogDisplay(Player(0), dial, false)
    if (GetClickedButton() == diabut[1]) then
        call SetUnitLifeBJ(target, 700)
        call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Human\\Heal\\HealTarget.mdl", target, "overhead"))
    endif
endfunction

function dialogAction takes nothing returns nothing
    set target = GetEnteringUnit()
    
    call DialogSetMessage(dial, "test")
    set diabut[1] = DialogAddButton(dial, "Heal hero", 1)
    set diabut[2] = DialogAddButton(dial, "Nevermind", 2)
    call DialogDisplay(Player(0), dial, true)
endfunction

//===========================================================================

function InitTrig_Diaalog takes nothing returns nothing
    local trigger trig1 = CreateTrigger()
    local trigger trig2 = CreateTrigger()
    
    call TriggerRegisterDialogEvent(trig1, dial)
    call TriggerRegisterEnterRectSimple(trig2, gg_rct_Region_001)
    call TriggerAddAction(trig1, function buttonClicked)
    call TriggerAddAction(trig2, function dialogAction)
endfunction
The dialog pops up, though no text or healing appears.
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
Dialogs( as far as I know ) cant be initialized in globals so you should try to set that variable in the init function or create an other trigger with a wait 0.00 then set and add event ;)
*sigh* I just said it worked for me, didn't I?

Map attached, as I can't see why it's failing for you :S
Just walk in the dark grass to see the dialog :)
 

Attachments

  • ShowDialog.w3x
    16.6 KB · Views: 75
Level 2
Joined
Dec 1, 2007
Messages
11
*sigh* I just said it worked for me, didn't I?

Map attached, as I can't see why it's failing for you :S
Just walk in the dark grass to see the dialog :)

That works just fine, so I copied that jass into my map, but it still doesn't work. Is it because I use jassnewgenpack?
Code:(again)
JASS:
globals
    dialog dial = DialogCreate()
    button array diabut
    unit target
endglobals

function buttonClicked takes nothing returns nothing
    call BJDebugMsg("gunnar")
    call DialogDisplay(Player(0), dial, false)
    
    if (GetClickedButton() == diabut[1]) then
        call BJDebugMsg("blab")
        call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Human\\Heal\\HealTarget.mdl", target, "overhead"))
        call TriggerSleepAction(2)
    endif
endfunction

function dialogAction takes nothing returns nothing
    set target = GetEnteringUnit()
    
    call DialogSetMessage(dial, "test")
    set diabut[1] = DialogAddButton(dial, "Heal hero", 1)
    set diabut[2] = DialogAddButton(dial, "Nevermind", 2)
    call DialogDisplay(Player(0), dial, true)
endfunction

//===========================================================================

function InitTrig_Dialog takes nothing returns nothing
    local trigger trig1 = CreateTrigger()
    local trigger trig2 = CreateTrigger()
    
    call TriggerRegisterDialogEvent(trig1, dial)
    call TriggerRegisterEnterRectSimple(trig2, gg_rct_Region_001)
    call TriggerAddAction(trig1, function buttonClicked)
    call TriggerAddAction(trig2, function dialogAction)
endfunction
I just don't get what's wrong..:vw_wtf:
 
Level 2
Joined
Dec 1, 2007
Messages
11
You MUST use JNGP to use this, that's how vJass works :p
So no, it's not that (you must save the map before testing it though).

By the way: what do you do with the local "target"?
And if it really doesn't work in your map only, may I see the map?

Sure, but don't mind about all the triggers, I'm just learning jass :3
 

Attachments

  • newtest.w3x
    85.8 KB · Views: 58
Level 28
Joined
Jan 26, 2007
Messages
4,789
Sure, but don't mind about all the triggers, I'm just learning jass :3
No problem, that's why you asked it here: to learn :D (Or to get your trigger fixed, whatever D:)
InitTrig_Dialog only runs if the trigger is named Dialog, not Diaalog.
This is why people should use initializers to avoid these kinds of mistakes.
I only use initializers for scopes/libraries (and I don't use too many of those).
Well, I'm not a "pure vJasser" anyway, some good old JASS now and then is still sweet.
 
Status
Not open for further replies.
Top